【问题标题】:documents4j conveter to pdf doesn't work without Microsoft word?没有 Microsoft Word,documents4j 转换为 pdf 不起作用?
【发布时间】:2019-07-29 07:41:08
【问题描述】:

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

【问题讨论】:

    标签: java ms-word converters documents4j


    【解决方案1】:

    documents4j 是一个通过连接到 MS Word 的转换文档。如果您没有运行实例,很遗憾,这将不起作用。

    【讨论】:

    • 我可以使用 libre office api for java 吗?(用于将 docx 转换为 pdf)
    • 如果您为它实现了自己的 IConverter,是的,您可以。然而,Libre Office 已经有了 Java API。
    • Liber office也需要安装?
    猜你喜欢
    • 1970-01-01
    • 2016-09-13
    • 2016-03-22
    • 1970-01-01
    • 2019-04-04
    • 1970-01-01
    • 2018-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多