哪个Java库可以帮助将包含形状和Word绘图的MS Word文档转换为PDF?



我正在尝试使用Java将扩展名为.docx的文件转换为PDF。我需要在MS Word中转换带有形状和绘图的文件。哪些库(开源或许可)将达到目的?

目前我一直在使用"org.apache.poi.xwpf.converter.pdf.PdfConverter"来达到目的,但它跳过了转换我的Word文档中的形状或绘图。我无法使用Aspose.words测试它。任何帮助也将不胜感激。

我用于转换的方法是:

public static void createPDFFromIMG(String sSourceFilePath,String sFileName, String sDestinationFilePath) throws Exception {
logger.debug("Entered into createPDFFromIMG()n");
logger.info("### Started PDF Conversion..");
System.out.println("### Started PDF Conversion..");
try {
if(sFileName.contains(".docx")) {
InputStream doc = new FileInputStream(new File(sSourceFilePath));
XWPFDocument document = new XWPFDocument(doc);
PdfOptions options = PdfOptions.create();
OutputStream out = new FileOutputStream(
new File(sDestinationFilePath + "/" + sFileName.split("\.")[0] + ".pdf"));
PdfConverter.getInstance().convert(document, out, options);
doc.close();
out.close();
System.out.println("### Completed PDF Conversion..");
logger.info("### Completed PDF Conversion..");
logger.debug("Exited from createPDFFromIMG()");
return;
}
}

我希望完整的Word文件能够转换为PDF,但是使用上述Java库转换的文件不包含docx文件中存在的绘图或形状。

实际上并不清楚为什么无法使用Aspose.Words进行测试。代码非常简单

Document doc = new Document("in.docx");
Doc.save("out.pdf");

您也可以使用免费的Aspose App(实际上基于Aspose.Words)进行测试 https://products.aspose.app/words/conversion

最新更新