Java POI Word 转 PDF

时间:2025-03-19 07:47:56

pom依赖:

<dependency>
    <groupId></groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.17</version>
</dependency>
<dependency>
    <groupId></groupId>
    <artifactId>-gae</artifactId>
    <version>2.0.1</version>
</dependency>

测试代码:

@Test
public void test() {
    FileInputStream fileInputStream = null;
    FileOutputStream fileOutputStream = null;
    
    try {
        fileInputStream = new FileInputStream("D:\\download\\");
        XWPFDocument xwpfDocument = new XWPFDocument(fileInputStream);
        PdfOptions pdfOptions = ();
        fileOutputStream = new FileOutputStream("D:\\download\\");
        ().convert(xwpfDocument,fileOutputStream,pdfOptions);
    } catch (FileNotFoundException e) {
        ();
    } catch (IOException e) {
        ();
    } finally {
        try {
            if (null != fileInputStream) {
                ();
            }
            if (null != fileOutputStream) {
                ();
            } 
        } catch (IOException e) {
            ();
        }
    }
}