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

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

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


开发之前的准备

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服务端口 默认是 8100
			configuration.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;"><a
	id="viewerPlaceHolder"
	style="width: 820px; height: 600px; display: block;float:left;"></a> <script
	type="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>





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值