实现WORD文档、PDF文档在线预览:具体实现流程

How to publish almost any document (word, excel, ..) to the web using FlexPaper ?

      之前在网上查找word文档在线预览的功能,类型邮箱中的文档预览,大多数的实现原理是使用FlexPaper来显示,有一个问题是FlexPaper 只支持将swf的文件,所有总是要先在本地把文档转换成pdf再转换成swf上传到服务器中,这显然不符合实际的需求,因为这对用户来说实在是太麻烦了。。。 即使是转换格式也是要在服务器端自动完成。

      Making documents available in the browser can be difficult when they are saved in many different formats. There are a number of products available that offer this service although many of them do this by simply using open source products that are available for free for you to use.

      One such open source product that can be used as a conversion engine is OpenOffice. This article describes how to use OpenOffice together with FlexPaper to display any format supported by OpenOffice directly in the browser.    

    

  •    使用SUN公司(,貌似现在是oracle的了,oracle又送给了apache组织)的Openoffice完成office(Word,Excel,Powerpoint)向pdf文档转化

1,将目录下的所有DOC格式的文件转化成PDF格式的文件
java -jar lib/jodconverter-cli-2.2.0.jar -f pdf *.doc
java -jar JConverterCommand.jar -f pdf F:\*.doc

2,转换制定的文件
java -jar lib/jodconverter-cli-2.2.0.jar document.doc document.pdf
java -jar JConverterCommand.jar c:\aaa.doc c:\aaa.pdf

介绍如下:

OpenOffice.org具有一个鲜为人知的特性就是其能够作为一个服务来运行,而这种能力具有一定的妙用。举例来说,你可以把openoffice.og变成一个转换引擎,利用这种转换引擎你可以通过网络接口或命令行工具对文件的格式进行转换,JODConverter可以帮助你实现OpenOffice.org的这种文件转换功能。

为了将OpenOffice.org作为一个转换引擎,你必须以服务的方式将它启动,使它在某个特定的端口监听连接,在Linux平台你可以用如下的命令启动openoffice.org:
soffice -headless -accept=”socket,port=8100;urp;”
在Windows平台, 使用如下命令:
“C:\Program Files\OpenOffice.org 3\program\soffice” -accept=”socket,port=8100;urp;”

JODConverter是基于java,你需要安装1.4或更高版本的java运行环境。下载最新版本的jodconverter-tomcat-x.x.x.zip,解压到某个目录,就可以启动 JODConverter
sh jodconverter-tomcat-2.2.2/bin/startup.sh
在浏览器打开http://localhost:8080/converter,你就可以看见一个简单的Web界面,选中需要转换的文件并确定格式,点击按钮就可以转换。也可以通过命令行对文件进行转换,如:
java -jar jodconverter-2.1.1/lib/jodconverter-2.2.2.jar loremipsum.odt loremipsum.pdf

 

转载于:https://my.oschina.net/usenrong/blog/197841

猜你喜欢

转载自blog.csdn.net/weixin_34015566/article/details/92028968