利用flexpaper开发类似百度文库功能,在线浏览WORD文档

来源:互联网 发布:linux网站管理系统 编辑:程序博客网 时间:2024/05/16 07:55

领导想要个在线文档浏览的系统,自己搜集了下网络上的资料,最后实现了一个类似的功能。

先上图,最终实现的效果。


开发之前的准备

1.openoffice

用来将word文档等转化成pdf 下载地址

http://sourceforge.net/projects/openofficeorg.mirror/files/localized/zh-cn/3.4.1/Apache_OpenOffice_incubating_3.4.1_Win_x86_install_zh-cn.exe/download

这里用的是openoffice3.4

2.swftools
用来把PDF转化成swf。我们最终就是在flexpaper中播放这个转化后的swf文件

下载地址

http://www.swftools.org/swftools-2013-04-09-1007.exe

3.jodconverter jar包

4.flexpaper_flash.js  

5.flexpaper

flexpaper : https://code.google.com/p/flexpaper/


第一步,先把上传的office文件转化成pdf文件

DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();configuration.setOfficeHome(OpenOffice_HOME);//openoffice安装路径configuration.setPortNumbers(Integer.parseInt(port_Str));//openoffice服务端口 默认是 8100configuration.setTaskExecutionTimeout(1000*60*5l);configuration.setTaskQueueTimeout(1000*60*60*24);OfficeManager officeManager = configuration.buildOfficeManager();officeManager.start(); //启动openoffice服务OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);converter.convert(inputFile, outputFile);//文档存放的绝对路径,outFile为生成pdf文件存放的位置officeManager.stop();


第二步,把pdf文件转化成swf,比较简单,因为在win环境,所以

String command = toolFile + " \"" + sourceFile + "\" -o  \"" + outFile+ "\" -f -T 9 -t -s storeallcharacters ";//toolFile pdf2swf.exe的绝对路径,如C:/Program Files/SWFTools/pdf2swf.exe,                 //souceFile pdf文件的绝对路径,outFile 生成的swf文件路径            try {Process process = Runtime.getRuntime().exec(command);System.out.println(loadStream(process.getInputStream()));System.err.println(loadStream(process.getErrorStream()));System.out.println(loadStream(process.getInputStream()));System.out.println("###--Msg: swf 转换成功");} catch (Exception e) {e.printStackTrace();}


最后在页面中引入


<div style="width:820px; float:left;"><aid="viewerPlaceHolder"style="width: 820px; height: 600px; display: block;float:left;"></a> <scripttype="text/javascript"> var fp = new FlexPaperViewer( 'flexpaper/flexpaper', 'viewerPlaceHolder', { config : { SwfFile : escape('swf的路径'), Scale : 0.6,  ZoomTransition : 'easeOut', ZoomTime : 0.5, ZoomInterval : 0.2, FitPageOnLoad : true, FitWidthOnLoad : true, FullScreenAsMaxWindow : false, ProgressiveLoading : false, MinZoomSize : 0.2, MaxZoomSize : 5, SearchMatchAll : false, InitViewMode : 'Portrait', PrintPaperAsBitmap : false,  ViewModeToolsVisible : true, ZoomToolsVisible : true, NavToolsVisible : true, CursorToolsVisible : true, SearchToolsVisible : true,     localeChain: 'zh_CN' }});        </script>        </div>





原创粉丝点击