1

我想使用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)
4

1 回答 1

1

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

于 2019-07-29T17:33:41.710 回答