• java 通过 冰蓝 word 转pdf ,最大程度包装pdf 样式和word接近


     所需依赖

    1. <dependency>
    2. <groupId>e-icebluegroupId>
    3. <artifactId>spire.doc.freeartifactId>
    4. <version>3.9.0version>
    5. dependency>
    6. <repositories>
    7. <repository>
    8. <id>com.e-iceblueid>
    9. <name>e-icebluename>
    10. <url>http://repo.e-iceblue.com/nexus/content/groups/public/url>
    11. repository>
    12. repositories>

     测试代码

    1. public static void main(String[] args) {
    2. Document document =new Document();
    3. document.loadFromFile("C:\\Users\\11949\\Desktop\\工作票3.docx");
    4. document.saveToFile("C:\\Users\\11949\\Desktop\\工作票3.pdf", FileFormat.PDF);
    5. }

    实际使用

    1. @GetMapping(value = "/exportWordTestPDFUrl")
    2. public R exportWordTestUrl(@RequestParam Map mapCon , HttpServletResponse response ) throws Exception {
    3. R resultBody = replaceWordDataService.replaceWord( mapCon );
    4. if(resultBody.getCode() == 0 ){
    5. byte[] array = null;
    6. ExportWordDTO data = (ExportWordDTO) resultBody.getData();
    7. XWPFTemplate template = data.getXwpfTemplate();
    8. ByteArrayOutputStream baos = new ByteArrayOutputStream();
    9. template.writeAndClose( baos );//文档写入流
    10. array = baos.toByteArray();
    11. baos.close();
    12. template.close();
    13. // 替换后的word转流
    14. InputStream inputStream = new ByteArrayInputStream( array ) ;
    15. Document document =new Document();
    16. document.loadFromStream(inputStream,FileFormat.Docx_2013);
    17. ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    18. document.saveToStream(outputStream, FileFormat.PDF);
    19. byte[] pdfArray = null;
    20. pdfArray = outputStream.toByteArray();
    21. outputStream.close();
    22. R upload =
    23. remoteFileService.upload(pdfArray, 1, applicationName, data.getOutFileName()+".pdf");
    24. if (null != upload && upload.getCode() == 0){
    25. // 将url 返回前端
    26. ResultFileModel fileModel = upload.getData();
    27. String path = fileModel.getAddress() + fileModel.getPath();
    28. return R.ok().data( path );
    29. }else {
    30. return R.fail().msg( "文件上传失败!" );
    31. }
    32. }
    33. return R.fail().msg(resultBody.getMsg());
    34. }

  • 相关阅读:
    算法刷题日志——二叉树
    关于HSV了解这些就够了,python-opencv获取图片精确hsv的值
    跨站脚本攻击xss攻击
    rviz添加qt插件
    CanTp03-CanTp 模块分段传输报文消息
    leetcode 42. 接雨水-java
    【qt】Qt Creator 设计界面与结果不一致问题
    windows访问服务器notebook(附pycharm)
    Android:窗口管理器WindowManager
    2023五一杯数学建模竞赛ABC题思路解析+代码+论文
  • 原文地址:https://blog.csdn.net/qq_36961226/article/details/126764607