系统版本:centos 7.0
相关插件:openoffice3、Jodconverter 、swftools、FlexPaper
实现语言:PHP
php实现百度文库在线预览整体思路:
1、将doc格式转换为pdf格式
2、pdf格式转换swf格式
3、使用FlexPaper插件在线播放swf格式
1. 安装openoffice3
wget .tw/packages/9/OOo_3.3.0_Linux_x86-64_install-rpm-wJRE_zh-CN.tar.gz
tar zxvf OOo_3.3.0_Linux_x86-64_install-rpm-wJRE_zh-CN.tar.gz
cd RPEM
rpm -ivh *.rpm --nodeps –force
安装后的默认目录是在:/opt/目录下面
启动服务:
/opt/3/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &
在CentOs下面会缺少黑体和宋体的,直接找到Windows下面的字体目录把黑体和宋体复制进去到目录
/opt//basis3.3/share/fonts/truetype/
执行fc-cache命令,fc-cache扫描字体目录并生成字体信息的缓存,然后应用程序就可以立即使用这些新安装的字体。
重启openoffice
2. 安装OpenOffice SDK3.3
wget http://ftp.nluug.nl/office/openoffice/stable/3.3.0/OOo-SDK_3.3.0_Linux_x86-64_install-rpm_en-US.tar.gz
tar zxvf OOo-SDK_3.3.0_Linux_x86-64_install-rpm_en-US.tar.gz
cd OOO330_m20_native_packed-1_en-US.9567/RPMS/
rpm -vih *.rpm
3. 安装jodconverter.2.2.2 ,安装了这个之后就已经可以实现DOC转PDF了。
这个安装很简单,直接上网站下一个这个回来。
解压,复制到一个目录里面去,就能直接用了,调用它里面的/lib/jodconverter-cli-2.2.2.jar这个就行,可以直接运行命令测试:
java -jar /usr/local/wenku/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar /tmp/1.doc /tmp/1.pdf
4. 安装swftools
中文支持安装:
mkdir –p /usr/share/xpdf
cd /usr/share/xpdf/
下载中文支持及字体库
wget ftp:///pub/xpdf/xpdf-chinese-simplified.tar.gz
wget /download/font.zip
tar zxvf xpdf-chinese-simplified.tar.gz
unzip font.zip
mv Gbsn00lp.ttf gkai00mp.ttf xpdf-chinese-simplified/CMap/ cd /usr/share/xpdf/xpdf-chinese-simplified
编辑,加入新增的字体
vim add-to-xpdfrc
内容如下:
cidToUnicodeAdobe-GB1/usr/share/xpdf/chinese-simplified/Adobe-GB1.cidToUnicode
unicodeMapISO--CN/usr/share/xpdf/chinese-simplified/ISO--CN.unicodeMap
unicodeMapEUC-CN/usr/share/xpdf/chinese-simplified/EUC-CN.unicodeMap
unicodeMapGBK/usr/share/xpdf/chinese-simplified/GBK.unicodeMap
cMapDirAdobe-GB1/usr/share/xpdf/chinese-simplified/CMap toUnicodeDir/usr/share/xpdf/chinese-simplified/CMap
displayCIDFontTT Adobe-GB1 /usr/share/xpdf/chinese-simplified/CMap/gkai00mp.ttf
保存后退出
SwfTool安装:
cd /usr/local/wenku
wget /swftools-0.9.1.tar.gz
tar zxvf swftools-0.9.1.tar.gz
cd swftools-0.9.1
./configure
make
make install
测试一下是否可用
yum install gcc gcc-c++
pdf2swf -o /usr/output.swf -T -z -t -f /usr/test1.pdf -s languagedir=/usr/local/share/xpdf/chinese-simplified -s flashversion=9
如果测试成功,那就是显示的问题了。
5. 用FlexPaper实现在线预览
这个是网上下载,看着demo改下JS就行了,里面是用的JS读取SWF的路径。