当前位置:   article > 正文

OpenOffice实现文件在线预览_jodconverter在线预览

jodconverter在线预览
  1. server.port=9999
  2. #使能
  3. jodconverter.local.enabled=true
  4. #OpenOffice安装地址
  5. jodconverter.local.office-home=C:/Program Files (x86)/OpenOffice 4
  6. #同时执行任务的个数
  7. jodconverter.local.max-tasks-per-process=10
  8. #设置端口号(任意设置)
  9. jodconverter.local.port-numbers=8110
  10. #controller工具参数
  11. online.buffer.path=C:/online_pdf/
  12. online.buffer.file.name=hello.pdf
  1. <!--jodconverter 核心包 -->
  2. <dependency>
  3. <groupId>org.jodconverter</groupId>
  4. <artifactId>jodconverter-core</artifactId>
  5. <version>4.2.2</version>
  6. </dependency>
  7. <!--springboot支持包,里面包括了自动配置类 -->
  8. <dependency>
  9. <groupId>org.jodconverter</groupId>
  10. <artifactId>jodconverter-spring-boot-starter</artifactId>
  11. <version>4.2.2</version>
  12. </dependency>
  13. <!--jodconverter 本地支持包 -->
  14. <dependency>
  15. <groupId>org.jodconverter</groupId>
  16. <artifactId>jodconverter-local</artifactId>
  17. <version>4.2.2</version>
  18. </dependency>
  1. package com.itheima.openoffice.controller;
  2. import org.apache.commons.io.IOUtils;
  3. import org.jodconverter.DocumentConverter;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.beans.factory.annotation.Value;
  6. import org.springframework.web.bind.annotation.GetMapping;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RestController;
  9. import javax.servlet.ServletOutputStream;
  10. import javax.servlet.http.HttpServletResponse;
  11. import java.io.File;
  12. import java.io.FileInputStream;
  13. import java.io.IOException;
  14. @RestController
  15. @RequestMapping("/open")
  16. public class OpenOfficeController {
  17. @Autowired
  18. private DocumentConverter documentConverter;
  19. @Value("${online.buffer.path}")
  20. private String bufferPath;
  21. @Value("${online.buffer.file.name}")
  22. private String bufferFileName;
  23. @GetMapping("/view")
  24. public void openOffice(HttpServletResponse response) {
  25. ServletOutputStream outputStream = null;
  26. FileInputStream fileInputStream = null;
  27. //获取需要转换的文件
  28. File file = new File("E:\\试一下.xlsx");
  29. //转换之后文件生成的地址
  30. File newFile = new File(bufferPath);
  31. if (!newFile.exists()) {
  32. newFile.mkdir();
  33. }
  34. try {
  35. documentConverter.convert(file).to(new File(bufferPath + bufferFileName)).execute();
  36. outputStream = response.getOutputStream();
  37. fileInputStream = new FileInputStream(new File(bufferPath + bufferFileName));
  38. IOUtils.copy(fileInputStream, outputStream);
  39. } catch (Exception e) {
  40. e.printStackTrace();
  41. } finally {
  42. try {
  43. if (fileInputStream != null) fileInputStream.close();
  44. if (outputStream != null) outputStream.close();
  45. } catch (IOException e) {
  46. e.printStackTrace();
  47. }
  48. }
  49. }
  50. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/428605
推荐阅读
相关标签
  

闽ICP备14008679号