【问题标题】:Java - Convert a docx to a pdf documentJava - 将 docx 转换为 pdf 文档
【发布时间】:2017-01-22 07:26:32
【问题描述】:

我正在尝试将包含徽标的 docx 文档转换为 pdf 文档。 我试过这个:

FileInputStream in=new FileInputStream(fileInput);
XWPFDocument document=new XWPFDocument(in);
File outFile=new File(fileOutput);
OutputStream out=new FileOutputStream(outFile);
PdfOptions options=null;
PdfConverter.getInstance().convert(document,out,options);

但在 pdf 文档中,徽标不在正确的位置。

有没有办法创建一个和docx文档一模一样的PDF?

【问题讨论】:

标签: java


【解决方案1】:

可以选择 document4j 吗?它将转换委托给本机应用程序。

这是通过将转换委托给任何本机应用程序来实现的,该应用程序可以理解将给定文件转换为所需的目标格式。

File wordFile = new File( ... );
File target = new File( ... );
IConverter converter = ... ;
Future<Boolean> conversion = converter
    .convert(wordFile).as(DocumentType.MS_WORD)
    .to(target).as(DocumentType.PDF)
    .prioritizeWith(1000) // optional
    .schedule();

您可以在安装了 Word 和 Excel 的 Windows 机器上使用“本地演示”快速测试转换是否符合您的要求:

git clone https://github.com/documents4j/documents4j.git
cd documents4j
cd documents4j-local-demo
mvn jetty:run

那就去http://localhost:8080

在此处查看完整文档: http://documents4j.com/#/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-07
    • 1970-01-01
    • 1970-01-01
    • 2013-11-08
    • 2021-04-23
    • 2017-04-14
    • 2022-12-18
    • 1970-01-01
    相关资源
    最近更新 更多