word转pdf依赖包无法引入

pom.xml中无法引入依赖包问题

今天碰到一个问题:需要转word然后在根据word转pdf,需要使用下边的这个依赖,但是在pom.xml引入不了这个依赖。。。

<dependency>
      <groupId>com.aspose</groupId>
      <artifactId>aspose-words</artifactId>
      <version>18.5.0718</version>
  </dependency>

解决方案

开发过程中经常遇到需要用某些http://maven.apache.org/中没有的jar包,这个时候可以用maven命令自己添加

  1. 下载要使用的jar包
  2. 用maven命令下载至自己的maven仓库中:
 mvn install:install-file -Dfile=aspose-words-18.5.0718.jar -DgroupId=com.aspose -DartifactId=aspose-words -Dversion=18.5.0718 -Dpackaging=jar
  1. 然后在pom中使用该依赖就可以了
  2. ![引入案列](https://img-blog.csdnimg.cn/12009fd0dbb3486cb13b53adf0548725.png在这里插入图片描述
    下面是word转pdf的工具类
package com.xxxxx;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import com.aspose.words.Document;
import com.aspose.words.License;
import com.aspose.words.SaveFormat;

public class WordPdfUtil {
    private static boolean license = false;

    public static void main(String[] args) {
//        doc2pdf("C:\\Users\\admin\\Desktop\\doc\\111.docx","C:\\Users\\admin\\Desktop\\doc\\aaa.pdf");
//        doc2pdf("C:\\Users\\admin\\Desktop\\doc\\222.docx","C:\\Users\\admin\\Desktop\\doc\\bbb.pdf");
//        doc2pdf("C:\\Users\\admin\\Desktop\\doc\\333.docx","C:\\Users\\admin\\Desktop\\doc\\ccc.pdf");
    }

    static {
        try {
            // license.xml放在src/main/resources文件夹下
            InputStream is = WordPdfUtil.class.getClassLoader().getResourceAsStream("license.xml");
            License aposeLic = new License();
            aposeLic.setLicense(is);
            license = true;
        } catch (Exception e) {
            license = false;
            System.out.println("License验证失败...");
            e.printStackTrace();
        }
    }

    /**
     * doc转pdf
     *
     * @param wordPath
     * @param pdfPath
     */
    public static void doc2pdf(String wordPath, String pdfPath) {
        // 验证License 若不验证则转化出的pdf文档会有水印产生
        System.out.println("进来了:"+license);
        if (!license) {
            System.out.println("License验证不通过...");
            return;
        }
        System.out.println("第二不:");
        try {
            System.out.println("第三不:");
            long old = System.currentTimeMillis();
            //新建一个pdf文档
            System.out.println("wordPath: 开始"+wordPath);
            System.out.println("pdfPath: 开始"+pdfPath);
            File file = new File(pdfPath);
            FileOutputStream os = new FileOutputStream(file);
            System.out.println("wordPath: "+wordPath);
            System.out.println("pdfPath: "+pdfPath);
            //Address是将要被转化的word文档
            Document doc = new Document(wordPath);
            System.out.println("doc=======");
            //全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
            doc.save(os, SaveFormat.PDF);
            System.out.println("全面支持DOC");
            long now = System.currentTimeMillis();
            os.close();
            //转化用时
            System.out.println("Word 转 Pdf 共耗时:" + ((now - old) / 1000.0) + "秒");
        } catch (Exception e) {
            System.out.println("Word 转 Pdf 失败...");
            e.printStackTrace();
        }
    }
}


特别注意安装的包名,版本,组id必须一一对应。不然同样依赖不进来,当时本人依赖是对应的pom版本不一样,导致卡在那里问一万个为什么,唉,大意失荆州。多注意些细节呀能稳中得意呀!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值