当前位置: 首页 > article >正文

aspose-words 跳过证书验证jar

优先用 aspose-words-19.3.jar ,不需要读取license.xml,导出后直接无水印,jar包最好直接放在项目resource目录下直接引用,要不下载不下来

   public static String doc2pdf(String fileName, String filePath) {
        try {
            String oldFile = filePath + fileName;
            String newFile = oldFile.substring(0, oldFile.lastIndexOf("."))+".pdf";

            File file = new File(newFile);  //新建一个空白pdf文档
            FileOutputStream os = new FileOutputStream(file);
            Document doc = new Document(oldFile);                    //Address是将要被转化的word文档
            ParagraphFormat pf=doc.getStyles().getDefaultParagraphFormat();
            pf.clearFormatting();
            doc.save(os, SaveFormat.PDF);//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
            return newFile;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

//先导出word然后转pdf


```java
public void exportFiveBsPdf(RiBaoVo.FiveBsParams dto, HttpServletResponse response) {
        OutputStream downLoadOutput = null;
        try {
            String date = dto.getRqb() + "至" + dto.getRq();
            RiBaoVo.FiveBsDataVo vo = getFiveBsData(dto);
            ClassPathResource classPathResource = new ClassPathResource("template/QGDLSCQK.docx");
            InputStream ins = classPathResource.getInputStream();
            //注册xdocreport实例并加载FreeMarker模板引擎
            IXDocReport report = XDocReportRegistry.getRegistry().loadReport(ins, TemplateEngineKind.Freemarker);
            //创建xdocreport上下文对象
            IContext context = report.createContext();
            //创建要替换的文本变量
            context.put("date", date);
            context.put("today", DateUtils.getStringDateShort());
            //context  put的值不能为null,会报错,用“”代替
            Class<? extends RiBaoVo.FiveBsDataVo> aClass = vo.getClass();
            Field[] fields = aClass.getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                String name = field.getName();
                String value = ObjectUtils.isEmpty(field.get(vo)) ? "" : field.get(vo).toString();
                context.put(name, value);
            }
            downLoadOutput = response.getOutputStream();

            ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
            report.process(context, byteArrayOutputStream);

            byte[] bytes = byteArrayOutputStream.toByteArray();
            InputStream inputStream=new ByteArrayInputStream(bytes);
            Document doc = new Document(inputStream);                
            ParagraphFormat pf=doc.getStyles().getDefaultParagraphFormat();
            pf.clearFormatting();
            doc.save(downLoadOutput, SaveFormat.PDF);//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换

            response.setContentType("application/pdf");
            response.setCharacterEncoding("utf-8");
            response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
            response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("全国电力生产情况.pdf", "utf-8"));
            response.setHeader("Content-Type", "application/octet-stream;charset=utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                if (downLoadOutput != null) {
                    downLoadOutput.flush();
                    downLoadOutput.close();
                    downLoadOutput = null;
                }
            } catch (IOException e1) {
                //e1.printStackTrace();
                System.out.println("Close ServletOutputStream error. type 55");
            }
        }
    }


http://www.kler.cn/a/152393.html

相关文章:

  • 【opencv】计算机视觉基础知识
  • 2023年亚太杯APMCM数学建模大赛A题水果采摘机器人的图像识别
  • 【Android】使用intent.putExtra()方法在启动Activity时传递数据
  • KaiwuDB 亮相中国 5G + 工业互联网大会,助力新型工业化
  • word模板导出word文件
  • git 如果只保存在本地没有保存到远程仓库
  • PPT 遇到问题总结(修改页码统计)
  • 计算机应用基础_错题集_PPT演示文稿_操作题_计算机多媒体技术操作题_文字处理操作题---网络教育统考工作笔记007
  • Win Server 2019远程桌面服务部署
  • ArkUI框架中的PersistentStorage和Environment深入详解【鸿蒙专栏-13】
  • 数据结构--->单链表
  • 应用于智慧油站的AI边缘计算盒子+AI算法软硬一体化方案
  • 点大商城V2.5.3分包小程序端+小程序上传提示限制分包制作教程
  • 跨平台IPTV播放器IPTVnator
  • 玩转大数据:3-Hadoop家族的力量与挑战
  • 2024年甘肃省职业院校技能大赛中职组 电子与信息类“网络安全”赛项竞赛样题-A卷
  • SpringSecurity自定义登录
  • 【机器学习】线性模型之逻辑回归
  • 报错AttributeError: module ‘cv2‘ has no attribute ‘ximgproc‘
  • STC15-串口通信打印输出数据printf函数与sprintf函数