documents4j 转换为 pdf 没有 Microsoft word 就不能工作?

documents4j conveter to pdf doesn't work without Microsoft word?

我想用 documents4j 将 docx 文件转换为 pdf,但我不想使用 MS word

有没有其他解决方案?

我使用了 Apache poi,但它在波斯语中无法正常工作

public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
    ByteArrayOutputStream bo = new ByteArrayOutputStream();

    InputStream in = new BufferedInputStream(new FileInputStream("d:\c.docx"));
    IConverter converter = LocalConverter.builder()
            .baseFolder(new File("D:\a"))
            .workerPool(20, 25, 2, TimeUnit.SECONDS)
            .processTimeout(5, TimeUnit.SECONDS)
            .build();

    Future<Boolean> conversion = converter
            .convert(in).as(DocumentType.MS_WORD)
            .to(bo).as(DocumentType.PDF)
            .prioritizeWith(1000) // optional
            .schedule();
    conversion.get();
    try (OutputStream outputStream = new FileOutputStream("D:\c.pdf")) {
        bo.writeTo(outputStream);
    } catch (IOException e) {
        e.printStackTrace();
    }
    in.close();
    bo.close();
}
}

我的错误:

[main] INFO com.documents4j.conversion.msoffice.MicrosoftWordBridge - From-Microsoft-Word-Converter was started successfully
[main] INFO com.documents4j.job.LocalConverter - The documents4j local converter has started successfully
[pool-1-thread-1] INFO com.documents4j.conversion.msoffice.MicrosoftWordBridge - Requested conversion from D:\a\b3106f03-c187-4059-bbd0-46b7bb4a1404\temp1 (application/vnd.com.documents4j.any-msword) to D:\a\b3106f03-c187-4059-bbd0-46b7bb4a1404\temp2 (application/pdf)
Exception in thread "main" java.util.concurrent.ExecutionException: Could not complete conversion
    at com.documents4j.job.FailedConversionFuture.get(FailedConversionFuture.java:35)
    at com.documents4j.job.FailedConversionFuture.get(FailedConversionFuture.java:10)
    at com.documents4j.job.AbstractFutureWrappingPriorityFuture.get(AbstractFutureWrappingPriorityFuture.java:205)
    at com.documents4j.job.AbstractFutureWrappingPriorityFuture.get(AbstractFutureWrappingPriorityFuture.java:10)
    at com.example.demo.DemoApplication.main(DemoApplication.java:31)
Caused by: com.documents4j.throwables.ConverterAccessException: The converter seems to be shut down
    at com.documents4j.util.Reaction$ConverterAccessExceptionBuilder.make(Reaction.java:117)
    at com.documents4j.util.Reaction$ExceptionalReaction.apply(Reaction.java:75)
    at com.documents4j.conversion.ExternalConverterScriptResult.resolve(ExternalConverterScriptResult.java:69)
    at com.documents4j.conversion.ProcessFutureWrapper.evaluateExitValue(ProcessFutureWrapper.java:48)
    at com.documents4j.conversion.ProcessFutureWrapper.get(ProcessFutureWrapper.java:36)
    at com.documents4j.conversion.ProcessFutureWrapper.get(ProcessFutureWrapper.java:11)
    at com.documents4j.job.AbstractFutureWrappingPriorityFuture.run(AbstractFutureWrappingPriorityFuture.java:78)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.base/java.lang.Thread.run(Thread.java:844)

documents4j 是一个通过桥梁将文档转换为 MS Word 的工具。不幸的是,如果您没有实例 运行,这将不起作用。