在linux下实现doc转pdf,再转swf,实现在线预览功能

首先需要在linux系统下面安装swftools,官网:http://www.swftools.org/
安装swftools需要安装freetype和jpeglib依赖
地址:
http://download.savannah.gnu.org/releases/freetype/freetype-2.5.3.tar.gz
http://www.ijg.org/files/jpegsrc.v9a.tar.gz
然后再编译安装swftools
编辑如果出现以下出错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
jpeg.c: In functionjpeg_load_from_mem’:
jpeg.c:331:30: error: ‘TRUE’ undeclared (first use in this function)
jpeg_read_header(&cinfo, TRUE);

^
jpeg.c: In functionjpeg_load’:
jpeg.c:380:30: error: ‘TRUE’ undeclared (first use in this function)
jpeg_read_header(&cinfo, TRUE);

^
jpeg.c: In functionjpeg_get_size’:
jpeg.c:462:30: error: ‘TRUE’ undeclared (first use in this function)
jpeg_read_header(&cinfo, TRUE);

^
make[1]: *** [jpeg.o] Error 1
make[1]: Leaving directory `/home/geekz/Downloads/swftools-0.9.2/lib'
make: *** [all] Error 2

那就将源文件的lib/jpeg.c文件中的TRUE和FALSE变量分别改成1和0,又或者在文件首部加入

1
2
#define TRUE 1
#define FALSE 0

swftools中文支持

1
2
mkdir –p /usr/share/xpdf
cd /usr/share/xpdf/

下载中文支持及字体库

1
2
3
4
5
6
wget ftp://ftp.foolabs.com/pub/xpdf/xpdf-chinese-simplified.tar.gz
wget http://www.nginxs.com/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

编辑,加入新增的字体

1
vim add-to-xpdfrc

内容如下:

1
2
3
4
5
6
7
cidToUnicodeAdobe-GB1/usr/share/xpdf/chinese-simplified/Adobe-GB1.cidToUnicode
unicodeMapISO-2022-CN/usr/share/xpdf/chinese-simplified/ISO-2022-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

保存后退出
要在浏览器里面复制中文到剪贴页不乱码,必须要在JS代码参数里面添加localeChain: ‘zh_CN’

安装unoconv:sudo apt-get install unoconv

1
exec("sudo unoconv -f pdf -o {$abPdfPath} {$abPath}", $output, $status);

需要赋予www-data对unoconv的执行权限
执行sudo visudo,在最后加上 www-data ALL=NOPASSWD:/usr/bin/unoconv
这样 www-data 就可以运行 unoconv 了