Java 工具类 | word文档 转 pdf 使用 jacob

long start = System.currentTimeMillis();
ActiveXComponent app = null;
try {
    app = new ActiveXComponent("Word.Application");
    app.setProperty("Visible", false);
    Dispatch docs = app.getProperty("Documents").toDispatch();
// filePath word的路径,,尽量使用绝对路径
    Dispatch doc = Dispatch.call(docs, "Open", filePath, false, true).toDispatch();
// file 获取的是 当前项目路径。。。保存的地址    
filePath = file + "\\wordTemplate\\"+ "商标申请合同.pdf";
    File tofile = new File(filePath);
    if (tofile.exists()) {
        tofile.delete();
    }
    Dispatch.call(doc, "SaveAs", filePath, DocUtil.getWdFormatPDF());
    Dispatch.call(doc, "Close", false);
    long end = System.currentTimeMillis();

} catch (Exception e) {
    System.out.println("Word转PDF出错:" + e.getMessage());
} finally {
    if (app != null) {
        app.invoke("Quit", DocUtil.getWdDoNotSaveChanges());
    }
}
注意 这里jacob要放在 jdk,bin和 jre bin 和 system32 里各一份,注意下载的是64还是32位。(具体另行研究。)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值