• 完美解决word转pdf(亲测有效)


    word搞了一天,找了无数的资料,以下这种方法是最好的。。。什么只能转3页了。。。什么字体库了。。。。各种坑

    就三步

    第一步:下载jar包,然后放在这里
    在这里插入图片描述

    第二步:引入jar包,放在pom.xml文件

    <dependency>
                <groupId>com.aspose</groupId>
                <artifactId>aspose-words</artifactId>
                <version>15.8.0</version>
                <scope>system</scope>
                <systemPath>${project.basedir}/lib/aspose-words-15.8.0-jdk16.jar</systemPath>
    </dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    第三步:写工具类

    package com.xxx.util;
    
    import com.aspose.words.Document;
    import com.aspose.words.License;
    import com.aspose.words.SaveFormat;
    import lombok.SneakyThrows;
    
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    
    public class AsposeUtil {
    
            /**
             * 加载license 用于破解 不生成水印
             */
            @SneakyThrows
            private static void getLicense() {
                try (InputStream is = AsposeUtil.class.getClassLoader().getResourceAsStream("License.xml")) {
                    License license = new License();
                    license.setLicense(is);
                }
            }
    
            /**
             * word转pdf
             * @param wordPath word文件保存的路径
             * @param pdfPath  转换后pdf文件保存的路径
             */
            @SneakyThrows
            public static void wordToPdf(String wordPath, String pdfPath) {
                getLicense();
                File file = new File(pdfPath);
                try (FileOutputStream os = new FileOutputStream(file)) {
                    Document doc = new Document(wordPath);
                    doc.save(os, SaveFormat.PDF);
                }
            }
    
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42

    最后就能直接用了,可以参考我的

     		String inPath = "D:\\/java" + "\\/123456.docx";
     		String outPath = "D:\\/java" + "\\/123456.pdf";
            AsposeUtil asposeUtil = new AsposeUtil();
            asposeUtil.wordToPdf(wordPath,pdfPath);
    
    • 1
    • 2
    • 3
    • 4

    以下可能就是你需要的jar包咯~
    链接: https://pan.baidu.com/s/1A4OZKApDA-CgcpmN-XaCag 提取码: 2f66 复制这段内容后打开百度网盘手机App,操作更方便哦

    觉得有帮助的话,帮点个赞哦~多谢

  • 相关阅读:
    [附源码]java毕业设计乒乓球俱乐部管理系统
    Hive大白话(●三●)
    Vue UI 组件库
    docker 可用镜像服务地址(2024.10.31亲测可用)
    我的单片机入门之旅
    微信小程序开发12 渐进增强:小程序的更新策略
    全面了解v-if和v-show的区别
    【Linux】权限完结
    第十二章 配置 Apache 以与 Web 网关配合使用 (Windows)
    使用CUDA计算GPU的理论显存带宽
  • 原文地址:https://blog.csdn.net/weixin_42804852/article/details/133859451