0

我使用 Spring MVC Web 项目,将 docx 文件转换为 pdf 时需要documents4j 库。Documents4j 可以正确地将 docx 转换为 pdf,但随后我的网络会话被注销。有谁知道为什么?

我正在使用 Spring mvc web 结构,我需要为 docx 转换 pdf 的documents4j。我用来转换的代码:

    File inputWord = new File("Tests.docx");
File outputFile = new File("Test_out.pdf");
try  {
    InputStream docxInputStream = new FileInputStream(inputWord);
    OutputStream outputStream = new FileOutputStream(outputFile);
    IConverter converter = LocalConverter.builder().build();
    converter.convert(docxInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
    outputStream.close();
    System.out.println("success");
} catch (Exception e) {
    e.printStackTrace();
}

我正在使用以下依赖项;

<dependency>
    <groupId>com.documents4j</groupId>
    <artifactId>documents4j-local</artifactId>
    <version>1.0.3</version>
</dependency>
<dependency>
    <groupId>com.documents4j</groupId>
    <artifactId>documents4j-api</artifactId>
    <version>1.0.3</version>
</dependency>
<dependency>
    <groupId>com.documents4j</groupId>
    <artifactId>documents4j-transformer-msoffice-word</artifactId>
    <version>1.0.3</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.7.13</version>
</dependency>

我的输出:

INFO com.documents4j.conversion.msoffice.MicrosoftWordBridge - From-Microsoft-Word-Converter was started successfully
INFO com.documents4j.job.LocalConverter - The documents4j local converter has started successfully
INFO com.documents4j.conversion.msoffice.MicrosoftWordBridge - Requested conversion from C:\a\b3106f03-c187-4059-bbd0-46b7bb4a1404\temp1 (application/vnd.com.documents4j.any-msword) to C:\a\b3106f03-c187-4059-bbd0-46b7bb4a1404\temp2 (application/pdf)
4

0 回答 0