欢迎来到我的博客

java word转 pdf

        <!-- https://mvnrepository.com/artifact/com.luhuiguo/aspose-words -->
        <dependency>
            <groupId>com.luhuiguo</groupId>
            <artifactId>aspose-words</artifactId>
            <version>22.4</version>
            <type>pom</type>
       </dependency>

代码如下:

package com.test.vn;

import com.aspose.words.Document;
import com.test.sdp.exception.support.BusinessException;

import java.io.File;
import java.io.FileOutputStream;
public class WordToPdf {
    /**
     ● @param wordPath word路径
     ● @param pdfPath  pdf输出路径

     */
    public static void textWordToPdf(String wordPath, String pdfPath) {
        FileOutputStream os = null;
        try {
            File file = new File(pdfPath);
            os = new FileOutputStream(file);
            Document doc = new Document(wordPath);
            doc.save(os, com.aspose.words.SaveFormat.PDF);
        } catch (Exception e) {
            throw new BusinessException("worldToPdf失败");
        } finally {
            if (os != null) {
}
        }
    }
    public static void main(String[] args) throws Exception {
        String wordPath = "F:\\工作\\PDF字体样式要求.docx";
        String pdfPath = "F:\\工作\\405nnn23.pdf";
        textWordToPdf(wordPath, pdfPath);
    }
}

 效果图如下:

image

 

image

 

posted @ 2025-11-06 20:29  八千轮回  阅读(10)  评论(0)    收藏  举报
人生三从境界:昨夜西风凋碧树,独上高楼,望尽天涯路。 衣带渐宽终不悔,为伊消得人憔悴。 众里寻他千百度,蓦然回首,那人却在灯火阑珊处。