您的位置:首页 > 其它

在线文档库系列:PDF文件转换为SWF格式

2012-07-09 00:00 211 查看
因工作原因,需要实现一个类似于百度文档在线查看的功能,经google/baidu,确定了以下技术路线:

1)客户端使用FlexPaper,对转换后的swf格式文件进行流式播放,节省带宽和响应时间;

2)使用SWFTools进行pdf到swf格式的转换;

3)使用tomcat作为webdav服务器,对文件进行存储和访问;

4)使用IT Hit WebDAV AJAX库开发文件管理模块,UI部分使用ExtJs 4。

目前大部分工作都已经完成,所以打算写几篇日志记录一下开发过程中遇到的问题,本文算是第一篇吧。

在线文档库的主要功能之一是在浏览器中直接查看文件,由于已经确定采用swf文件格式,因此需要对pdf文件进行转换。转换工具选择了SWFTools。以下博文对这一选择帮助很大,特此向作者致敬: http://hi.baidu.com/stone_kings/item/da5acb36dc539a372f20c463 http://hi.baidu.com/stone_kings/item/f3054f2e93b7ef0c73863e63
1、转换工具下载
SWFTools是以GPL协议发布一组Flash文件处理工具集,其中包含了将pdf转为swf的工具。下载地址为:
http://www.swftools.org/
使用的软件版本为:0.9.2

2、中文字符集下载

SWFTools并未包含中文字体,所以需要借助另外一个开源项目xpdf。xpdf是pdf查看工具,其多语言支持包中包含有中文字符集文件。下载地址为:
http://www.foolabs.com/xpdf/download.html
当前版本为3.03,只需下载以下这一文件:

Chinese/simplified: xpdf-chinese-simplified.tar.gz

下载完成后,将文件解压缩到SWFTools安装目录下,如:

D:\program\SWFTools\xpdf-chinese-simplified

3、进行文档转换

SWFTools安装目录下的pdf2swf.exe是进行pdf到swf转换的命令行工具,假设源文件为source.pdf,输出的目标文件为target.swf,则命令格式为:

D:\program\SWFTools\pdf2swf -f -T 9 -t -G -s subpixels=1.5 -s storeallcharacters -s languagedir=xpdf-chinese-simplified "source.pdf" -o "target.swf"
其中主要参数的含义是:

-f Fonts should be embedded, improves searchability in the document

-T 9 Sets the target flash version to 9, improves stability

-t Inserts a stop between each frame, improves stability

-G Makes the document smaller and faster to render

-s subpixels=1.5 Adjusts image resolution in the document. Should be used in cases where the document contains lots of large images. The value (1.5) can be experimented with to archive desired quality.

-s storeallcharacters Stores all character information about the texts in the document, improves searchability

-s languagedir=xpdf-chinese-simplified Add an xpdf language directory
更完整的参数解释清查阅:
http://wiki.swftools.org/index.php/Pdf2swf
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息