Word、Excel、PPT转Pdf

这篇博客介绍了如何利用Jacob库将Word、Excel和PPT文件转换为PDF格式。首先,需要从Jacob官网获取相应版本的dll文件,并将其放置在JRE的bin目录下。接着,确保系统中已安装Office或WPS软件,最后重启开发环境或服务即可完成转换。
摘要由CSDN通过智能技术生成

使用Jacob转Word、Exce、PPT为PDF文件

1.去jacob的官网下载需要的版本
2.将jacob-xx版本-x64.dll(系统为64位)/jacob-xx版本-x86.dll(系统为32位)文件放到jdk安装目录下jre/bin目录中
3.重启开发软件,或重启相关服务
4.系统中必须装有office或WPS软件

package com.test.util;

import com.test.util.DateUtils;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.Date;

public class PdfUtil {
    private static Logger logger = LoggerFactory.getLogger(PdfUtil.class);

    /**
     * Word转换成PDF
     *
     * @param wordPath 目标word的路径
     * @param pdfName 目标生成pdf的名字
     * @return
     */
    public static String WordToPdf(String wordPath, String pdfName) {
        logger.info("=============== Word 转换 Pdf 开始 ===============");
        File wordFile = new File(wordPath);
        if (!wordFile.exists()) {
            logger.error("word文件不存在");
            return null;
        }
        ActiveXComponent app = null;
        Dispatch document = null;
        String pdfpath = "目标PDF的生成路径" + DateUtils.format(new Date(), "yyyyMMdd") + "/";
        try {
            ComThread.InitSTA(true);
            // 打开word
            app = new ActiveXComponent("Word.Application");
            // 获得word中所有打开的文档
            // Dispatch documents = app.getProperty("Documents").toDispatch();
            logger.info("&#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值