java实现附件预览(openoffice+PDF.js)

java实现附件预览(openoffice+PDF.js,将office文档,通过openoffice工具转换为PDF文件,使用PDF.js进行前端展示

是对openoffice+swftools+flexpaper的升级版,减少一次swf文件转换,及flexpaper只能预览十页内容,原文:http://blog.csdn.net/z69183787/article/details/17468039

 


 

现支持的转换格式如下:

private static String[] docFileLayouts = {".txt",".doc",".docx",".wps",".xls",".xlsx",".et",".ppt",".pptx",".dps"};//office办公软件格式
private static String[] imgFileLayouts = {".jpg",".gif",".jpeg",".png",".bmp"};//图片格式
private static String[] pdfFileLayouts = {".pdf"};//pdf格式

如有其它格式需要,可以对转换格式进行扩展,

 

1、 安装Apache_OpenOffice_4.1.2_Win_x86_install_en-US.exe,

下载连接:http://www.openoffice.org/download/index.html

2、 添加环境变量path=D:\Program Files (x86)\OpenOffice 4\program

3、 执行open_office_service.bat脚本,并,查看进程soffice是否运行

4、 Action新增方法

/**
 * .解析文章内容到PDF
 * @param request
 * @param modelMap
 * @param baseAddition
 */
private void initPDF(ServletWebRequest request,ModelMap modelMap,
              BaseAdditionbaseAddition) {
       Stringpath = "";
       if("".equals(baseAddition.getExpandOne()) || baseAddition.getExpandOne()==null){
              path= KAPath + baseAddition.getOperationId()+"/"+baseAddition.getAdditionId()+"/";
       }
       // 调用转换类DocConverter,并将需要转换的文件传递给该类的构造方法
       DocConverterd = new DocConverter(baseAddition);
       // 调用conver方法开始转换,先执行doc2pdf()将office文件转换为pdf;再执行pdf2swf()将pdf转换为swf;
       d.conver();
       // 调用getPdfPath()方法,打印转换后的pdf文件路径
       Stringpdfpath = request.getRequest().getContextPath()+path+d.getPdfName();
       // 将相对路径放入sessio中保存
       modelMap.put("pdfPath", pdfpath);
}

4、前端jsp,PDF加载展示

<!--内容-->
<div class="mim_content">
<iframe width="100%"height="700px" src="<%=basePath %>js/pdf/web/viewer.html?file=${pdfPath}"></iframe>
</div>

注:${pdfPath},

       a.PDF文件路径必须为项目路径

       b.文件名称不能包含中文s

5、切换到演示模式,由于使用iframe引入pdf页,全屏模式无法使用,具体原因可问度娘,这里只给出全屏显示思路。编辑viewer.js:

       a.将全屏按扭显示

/*if (!PDFView.supportsFullscreen) {
    document.getElementById('presentationMode').classList.add('hidden');
    document.getElementById('secondaryPresentationMode').
      classList.add('hidden');
  }*/
       b.更改按扭点击事件为自定义处理

request: function presentationModeRequest() {
  	//引用knowledgeLuceneDetail.jsp
	if(parent.document.IsFullScreen==null || !parent.document.IsFullScreen){
		parent.launchFullscreen();
	}else{
		parent.exitFullscreen();
	}
    return true;
  }
       c.函数可以隐藏不相关div,可以全屏显示,这里使用提隐藏div

	var docHtml = document.documentElement;
	var docBody = document.body;
	var videobox = document.getElementById('content');
	var mi_main_div = $("#mi_main_div");
	var module_info_div = $("#module_info_div");
	var module_info_2_div = $("#module_info_2_div");
	//進入全屏
	function launchFullscreen() {
			var cssText = 'width:100%;height:100%;overflow:hidden;';
			mi_main_div.hide();
			module_info_2_div.hide();
			docHtml.style.cssText = cssText;
			docBody.style.cssText = cssText;
			videobox.style.cssText = cssText + ';' + 'margin:0px;padding:0px;';
			module_info_div.removeClass('module_info');
			document.IsFullScreen = true;
	}
	//退出全屏
	function exitFullscreen() {
			mi_main_div.show();
			module_info_2_div.show();
			docHtml.style.cssText = "";
			docBody.style.cssText = "";
			videobox.style.cssText = "";
			module_info_div.addClass('module_info');
			document.IsFullScreen = false;
	}

js、java代码,有一些垃圾代码,大家请见量,有觉得不爽的地方,可以自己优化。

相关文件PDF.js+源码,请超链:http://download.csdn.net/detail/shnsvyu/9573577

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值