[英]how to convert docx files into PDF using Java in 2021?
I'm trying to convert docx files into PDF with Java in Windows OS.我正在尝试使用 Windows 操作系统中的 Java 将 docx 文件转换为 PDF。 All the alternatives that I found seems to be deprecated or there are not compatibilities between libraries.
我发现的所有替代方案似乎都已被弃用,或者库之间不兼容。 For example I found that
apache poi
can convert docx into PDF but the solutions I found are from 10 years ago.例如,我发现
apache poi
可以将 docx 转换为 PDF 但我找到的解决方案是 10 年前的。
Also I found documents4j
, but the same problem: I get a lot of exceptions.我也找到了
documents4j
,但同样的问题:我遇到了很多异常。
is there some simple way to do the conversion?.有没有一些简单的方法来进行转换?
Or what libraries are currently working to perform the conversion?或者哪些库目前正在执行转换?
All this answers are extracted from: http://www.techwaregeeks.com/word-processing/convert-docx-to-pdf-using-java-top-word-to-pdf-java-libraries/所有这些答案均来自: http://www.techwaregeeks.com/word-processing/convert-docx-to-pdf-using-java-top-word-to-pdf-java-libraries/
Aspose.Words : Aspose.Words :
Document wordDoc = new Document("document.docx"); //convert docx to pdf wordDoc.save("docx to pdf.pdf");
Spire.DOC : Spire.DOC :
String inputFile="data/Sample.docx"; String outputFile="output/toPDF.pdf"; //create word document Document document = new Document(); document.loadFromFile(inputFile); //save the document to a PDF file. document.saveToFile(outputFile, FileFormat.PDF);
GroupDocs.Converter : GroupDocs.Converter :
Converter converter = new Converter("sample.docx"); PdfConvertOptions options = new PdfConvertOptions(); converter.convert("converted.pdf", options);
XtremeDocumentStudio : XtremeDocumentStudio :
// document(s) that are not installed in OS Fonts Directory.
Framework.setUserFontsDirectory("C:\\FontsCollection\\");
// Create instance of DocumentConverter.
DocumentConverter dc = new DocumentConverter();
try {
// Specify the input and output file names.
dc.convertToFile("./sample.docx", "./sample.pdf");
}```
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.