完美的word转pdf

本文介绍了如何在Java中进行Word到PDF的转换,包括引入依赖、使用工具类以及控制器层的测试,支持doc和docx格式,同时提供在线预览和附件下载的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

话不多说,首先导入依赖包

这篇文章是转载的别人的文章 仅用于做本地保存
原文链接

<!-- documents4j word转pdf -->
        <dependency>
            <groupId>com.documents4j</groupId>
            <artifactId>documents4j-local</artifactId>
            <version>1.1.5</version>
        </dependency>
        <dependency>
            <groupId>com.documents4j</groupId>
            <artifactId>documents4j-transformer-msoffice-word</artifactId>
            <version>1.1.5</version>
        </dependency>

util工具类

import com.documents4j.api.DocumentType;
import com.documents4j.api.IConverter;
import com.documents4j.job.LocalConverter;
import java.io.*;
public class PdfUtil {
   
   
  /**
   * word转pdf
     * @param wordFilePath word文件路径
     * @param pdfFilePath  pdf文件路径
     * @return 成功或失败
     */
    public static boolean docxToPdf(String wordFilePath, String pdfFilePath) {
   
   
        boolean res
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值