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

用java实现word(docx)转换为pdf格式文档(简单版)

导入依赖

<dependency>
            <groupId>com.documents4j</groupId>
            <artifactId>documents4j-local</artifactId>
            <version>1.0.3</version>
        </dependency>
        <dependency>
            <groupId>com.documents4j</groupId>
            <artifactId>documents4j-transformer-msoffice-word</artifactId>
            <version>1.0.3</version>
        </dependency>

 代码

    //word文档替换成pdf文档
    private static void replaceWordToPdf(String wordPath, String pdfPath){
        File inputWord = new File(wordPath);
        File outputFile = new File(pdfPath);
        try  {
            InputStream docxInputStream = new FileInputStream(inputWord);
            OutputStream outputStream = new FileOutputStream(outputFile);
            IConverter converter = LocalConverter.builder().build();
            converter.convert(docxInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
            outputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

注意:需要获取到本地的word文件地址;


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

相关文章:

  • Linux Mem -- MTE in AArch64 Linux
  • CTF-WEB: 利用iframe标签利用xss,waf过滤后再转换漏洞-- N1ctf Junior display
  • 微信小程序实战项目001:NBA球队太阳队简介
  • 掌控系统性能的利器:自动化系统性能监控工具
  • 成本哪个更低更好用?分析对比大模型OCR、传统OCR和深度学习OCR
  • RabbitMQ配置SSL证书
  • Elasticsearch 滚动索引创建指南
  • DeepSeek模型集成到java中使用(阿里云版)超简单版
  • MongoDB 常用命令速查表
  • 恒创科技:如何重新启动 Windows 服务器
  • 第39周:猫狗识别 2(Tensorflow实战第九周)
  • Effective Objective-C 2.0 读书笔记——内存管理(上)
  • springboot如何将lib和jar分离
  • 2025.2.14——1400
  • 100N03-ASEMI豆浆机专用MOS管100N03
  • Linux查找占用的端口,并杀死进程的简单方法
  • 【教程】MySQL数据库学习笔记(七)——多表操作(持续更新)
  • Python基于Django的漏洞扫描系统【附源码、文档说明】
  • 自有证书的rancher集群使用rke部署k8s集群异常
  • 使用Opencv方法进行模板匹配