Aspose.words使用

这篇博客介绍了如何手动将Aspose Words的jar包安装到Maven仓库,并提供了一个Java方法`AsposeWordsUtils.doc2pdf()`用于将Word文档转换为PDF。该方法读取指定的Word文件,然后将其转化为PDF并保存,同时还输出了转换所花费的时间。
摘要由CSDN通过智能技术生成

1.手动安装jar到到maven仓库
mvn install:install-file -DgroupId=com.aspose -DartifactId=aspose-words -Dversion=18.8 -Dpackaging=jar -Dfile=C:/Users/29265/Desktop/aspose-words-19.5jdk.jar

在这里插入图片描述
2.写一个方法类

public class AsposeWordsUtils {

    /**
     * Word转PDF操作
     *@param sourcerFile 源文件
     *@param targetFile 目标文件
     */
    public static void doc2pdf(String sourcerFile,String targetFile) {

        try {
            long old = System.currentTimeMillis();
            File file = new File(targetFile);  //新建一个空白pdf文档
            FileOutputStream os = new FileOutputStream(file);
            Document doc = new Document(sourcerFile);                    //sourcerFile是将要被转化的word文档
            doc.save(os, SaveFormat.PDF);//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
            os.close();
            long now = System.currentTimeMillis();
            System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");  //转化用时
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //测试Word转PDF
    public static void main(String[] args) {
        doc2pdf("C:\\Users\\29265\\Desktop\\1.docx","C:\\Users\\29265\\Desktop\\1.pdf");
    }
}

参考:https://blog.csdn.net/weixin_39643007/article/details/93341886

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

java后端指南

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值