因为PageOffice集成了Thymeleaf,所以需要在resources目录下新建如下页面

Index.html点击预览操作页面

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"><head><title>Index</title><script type="text/javascript" src="jquery.min.js"></script><script type="text/javascript" src="pageoffice.js" id="po_js_main"></script></head><body><h1 th:inline="text">文件预览</h1><a href="javascript:POBrowser.openWindowModeless('/word?filepath=/opt/oa/enclosure/notice/1.doc','width=1200px;height=800px;');">打开文件 </a></body>
</html>

Word.html预览页面

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"><head><title>Hello World!</title><script type="text/javascript">function Save() {document.getElementById("PageOfficeCtrl1").WebSave();}</script><script type="text/javascript">function AddSeal() {try{document.getElementById("PageOfficeCtrl1").ZoomSeal.AddSeal();}catch (e){ };}</script></head><body><h1 th:inline="text"></h1><div style="width:1000px;height:700px;" th:utext="${pageoffice}"></div></body>
</html>

在application.yml中配置thymleaf和PageOffice的许可证书和印章密码

spring:application:name: testthymeleaf:prefix: classpath:/templates/suffix: .htmlcache: false
posyspath: /home/version
popassword: 111111

在pom中添加所需依赖

 <!-- 添加Sqlite依赖(可选:如果不需要使用印章功能的话,不需要添加此依赖 )--><dependency><groupId>org.xerial</groupId><artifactId>sqlite-jdbc</artifactId><version>3.7.2</version></dependency><!-- 添加PageOffice依赖(必须) --><dependency><groupId>com.zhuozhengsoft</groupId><artifactId>pageoffice</artifactId><version>4.4.0.4</version></dependency><!-- thymeleaf --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional></dependency>

Controller层

import com.zhuozhengsoft.pageoffice.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.util.Map;/*** PageOffice在线预览*/
@RestController
public class PageOfficeController {private Logger logger = LoggerFactory.getLogger(PageOfficeController.class);@Value("${posyspath}")private String poSysPath;@Value("${popassword}")private String poPassWord;@RequestMapping(value = "/index", method = RequestMethod.GET)public ModelAndView showIndex() {ModelAndView mv = new ModelAndView("Index");return mv;}/*** 打开文件** @return*/@RequestMapping("/word")public ModelAndView word(HttpServletRequest request, Map<String, Object> map, @RequestParam("filepath") String filepath) {//word、excel、ppt服务组件PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);poCtrl.setServerPage("/poserver.zz");//设置服务页面poCtrl.setTitlebar(true); // 隐藏标题栏(pageoffice的标题)poCtrl.setMenubar(false); // 隐藏菜单栏(文件一个设置)poCtrl.setOfficeToolbars(false);// 隐藏Office工具条(word 的编辑按钮)poCtrl.setCustomToolbar(false);// 隐藏自定义工具栏(保存 关闭 全屏)//poCtrl.addCustomToolButton("保存","Save",1);//添加自定义保存按钮//poCtrl.addCustomToolButton("盖章","AddSeal",2);//添加自定义盖章按钮//poCtrl.setSaveFilePage("/save");//设置处理文件保存的请求方法//pdf服务组件PDFCtrl pdfCtrl = new PDFCtrl(request);pdfCtrl.setServerPage("/poserver.zz");pdfCtrl.setTitlebar(true); // 隐藏标题栏(pageoffice的标题)pdfCtrl.setMenubar(false); // 隐藏菜单栏(文件一个设置)pdfCtrl.setCustomToolbar(false);// 隐藏自定义工具栏(保存 关闭 全屏)//String path = path.replace("/", "\\\\");//windows路径转换 Windows下路径d:\\file\\test.doc Linux下路径"file://" + /home/mobileoa/files2019_05_28/test.docString path = "file://"+filepath;logger.info("路径" + path);String suffix = path.substring(path.lastIndexOf(".") + 1);if ("doc".equals(suffix) || "docx".equals(suffix)||"DOC".equals(suffix) || "DOCX".equals(suffix)) {poCtrl.webOpen(path, OpenModeType.docReadOnly, "张三");map.put("pageoffice", poCtrl.getHtmlCode("PageOfficeCtrl1"));} else if ("xls".equals(suffix) || "xlsx".equals(suffix)||"XLS".equals(suffix) || "XLSX".equals(suffix)) {poCtrl.webOpen(path, OpenModeType.xlsReadOnly, "张三");map.put("pageoffice", poCtrl.getHtmlCode("PageOfficeCtrl1"));} else if ("ppt".equals(suffix) || "pptx".equals(suffix)||"PPT".equals(suffix) || "PPTX".equals(suffix)) {poCtrl.webOpen(path, OpenModeType.pptReadOnly, "张三");map.put("pageoffice", poCtrl.getHtmlCode("PageOfficeCtrl1"));} else if ("pdf".equals(suffix)||"PDF".equals(suffix)) {pdfCtrl.webOpen(path);map.put("pageoffice", pdfCtrl.getHtmlCode("PageOfficeCtrl1"));}ModelAndView mv = new ModelAndView("Word");return mv;}/*** 保存** @return*/
@RequestMapping("/save")
public void saveFile(HttpServletRequest request, HttpServletResponse response) {FileSaver fs = new FileSaver(request, response);fs.saveToFile("d:\\" + fs.getFileName());fs.close();
}/*** 添加PageOffice的服务器端授权程序Servlet(必须)** @return*/
@Bean
public ServletRegistrationBean servletRegistrationBean() {com.zhuozhengsoft.pageoffice.poserver.Server poserver = new com.zhuozhengsoft.pageoffice.poserver.Server();poserver.setSysPath(poSysPath);//设置PageOffice注册成功后,license.lic文件存放的目录ServletRegistrationBean srb = new ServletRegistrationBean(poserver);srb.addUrlMappings("/poserver.zz");srb.addUrlMappings("/posetup.exe");srb.addUrlMappings("/pageoffice.js");srb.addUrlMappings("/jquery.min.js");srb.addUrlMappings("/pobstyle.css");srb.addUrlMappings("/sealsetup.exe");return srb;
}/*** 添加印章管理程序Servlet(可选)** @return*/
@Bean
public ServletRegistrationBean servletRegistrationBean2() {com.zhuozhengsoft.pageoffice.poserver.AdminSeal adminSeal = new com.zhuozhengsoft.pageoffice.poserver.AdminSeal();adminSeal.setAdminPassword(poPassWord);//设置印章管理员admin的登录密码adminSeal.setSysPath(poSysPath);//设置印章数据库文件poseal.db存放的目录ServletRegistrationBean srb = new ServletRegistrationBean(adminSeal);srb.addUrlMappings("/adminseal.zz");srb.addUrlMappings("/sealimage.zz");srb.addUrlMappings("/loginseal.zz");return srb;
}

}

PageOffice在线预览word/excel/ppt/pdf相关推荐

  1. 关于在线预览word,excel,ppt,pdf的需求处理方法。

    参考文档:http://www.cnblogs.com/wolf-sun/p/3574278.html 我选用的方案:先用office com组件生成pdf,然后使用pdf.js在线预览pdf文档.在 ...

  2. 前端在线预览word,excel,pdf

    前端在线预览word,excel,pdf 预览Word 预览pdf 预览Excel 预览Word 微软的在线预览功能,可以预览word.ppt.Excel.PDF 局限: 需要外网能访问文件,如果是只 ...

  3. Vue 预览word,excel,ppt等office文档-内网访问(基于onlyoffice,后端返回文件流)

    Vue 预览word,excel等office 先看效果!! 需求背景:在前端页面中预览office文件且是内网访问,服务器不可访问外网的前提. 因此微软的接口就废掉了,因为他接口的条件是可以访问外网 ...

  4. vue预览word,excel,pptx,pdf文件

    vue预览word,excel,pptx,pdf文件 1.做word,excel,pptx的预览,要先确定文件路径访问是通过域名的url来预览,不可以通过IP的url来访问 先把文件路径的url进行u ...

  5. html画布显示PPT,【Web前端问题】有没有办法让HTML5 canvas显示/预览word/excel/powerpoint 文档?...

    目前想实现类似百度文库那样的在线文档预览,但是他们使用的一般都是Flash,而HTML5 canvas可以在大多数情况下代替Flash,那么有没有办法让canvas显示/预览Office文档? 如果不 ...

  6. mvc直接在html页面预览pdf,Asp.net MVC 实现在线预览word、excel、ppt、pdf文件

    在线预览word.excel.ppt 原理:主要是引用第三方Dll使本地word.excel.ppt文件转换成Html 需要引用 : Aspose.Cells.dll Aspose.Slides.dl ...

  7. (开源kkFileView、kkOffice)在线预览word、pdf、ofd、excel、ppt、压缩包、图片等等

    (开源kkFileView.kkOffice)在线预览word.pdf.ofd.excel.ppt.压缩包.图片等 前言 此项目为文件文档在线预览项目解决方案,对标业内付费产品有[永中office][ ...

  8. 使用永中文档实现java在线预览Word,Excel,Pptx,Pdf

    使用永中文档实现java在线预览Word,Excel,Pptx,Pdf 永中文档提供了在线预览的功能 永中开发者文档 如果需要直接运行,请直接修改代码中的两个参数 转换类型在下方,根据传入以及输出类型 ...

  9. 前端页面预览word_详解html实现在线预览word、excel、pdf等文件的功能(附代码)_WEB前端开发...

    JavaScript判断"字典"为空的方法_WEB前端开发 字典是一种存储键值对的数据结构,Javascript中的Object类内部即实现为一个字典,本文就来为大家介绍一下判断字 ...

  10. Springboot 超简单实现在线预览,Word文档 doc、xlsx、pdf、txt等

    前言 PDF.TXT 只要资源可访问,根本就不需要进行任何处理,直接访问查看就完事了. 也是因为这个PDF可以直接查看(现在浏览器基本支持了),那么我们实现Word文档在线预览,其实也是 把WORD文 ...

最新文章

  1. SAP QM 在Quality Notification里维护Internal Note
  2. centso7 install Mariadb
  3. hive插入表的insert 执行计划_0651-6.2.0-启用Sentry后Impala执行SQL失败问题分析
  4. 放置奇兵 算法 月度活动 破碎时空记录 第七关 阿姨(阿伊达)+暗战(阿斯布)
  5. python是什么和c++是什么区别_c++和python的区别有哪些
  6. fhq treap ------ luogu P3369 【模板】普通平衡树(Treap/SBT)
  7. 03—Shell脚本编写规范
  8. java库里_java8之StringJoiner。终于有像guava类库里的功能了
  9. 坐标偏差大_三坐标常见撞针原因,总结的太到位了!
  10. Json 语法 格式
  11. MySQL Query Cache 小结
  12. 使用普通asp.net编程方式开发WAP应用的可行性
  13. VBA教程初级(一):简单宏
  14. 【转载】C# ListView控件的一些用法
  15. Google Earth Engine 教程——栅格矢量数据转化和导出
  16. 2022 年,阿里内推 Java 后端面试题,文末附面试福利
  17. 叮咚! 你有一份节日祝福请查收~
  18. MATLAB单点定位程序设计思路
  19. 高斯与最小二乘法的故事
  20. 用ardupilot 做无人船项目的总结

热门文章

  1. matlab2018A配置cuda,使用教程 | matlab 2018a + cuda 10.1 + vs 2017
  2. QAM识别算法matlab,16qam调制识别matlab
  3. 增加了ssl证书后websocket连接失败
  4. 非极大值抑制(PyTorch-YOLOv3代码解析一)
  5. 安装VMware时勾选增强型键盘驱动程序有什么用?
  6. linux怎么进入mnt目录,「Linux基础知识」Linux路径的表示方式
  7. 上海图书馆e卡通阅读器差强人意
  8. 利用vue.js实现一个砍价小程序
  9. cad立体图怎么旋转看图_教大家CAD迷你看图如何旋转图纸
  10. Windows 下使用苹果鼠标、键盘