I have used aspose-words and document4j to convert Word to PDF, but they depend on the rendering engine to get the layout. There is a difference in the fonts, font sizes, and format of Word and PDF files generated on UNIX compared to Windows. I tried using Apache POI, but the conversion was not good.
//using document4j
InputStream docxInputStream =new FileInputStream("input.docx");
OutputStream outputStream = new FileOutputStream("output.pdf");
IConverter converter = LocalConverter.builder().build();
outputStream.close();
converter.convert(docxInputStream).as(DocumentType.DOCX)
.to(outputStream).as(DocumentType.PDF).execute();
converter.shutdown()
//using aspose word
Document doc=new Document(new FileInputStream(filePath));
String outputFilePath="output.pdf";
doc.save(outputFilePath,SaveFormat.PDF);
//using apache poi
InputStream doc = new FileInputStream(new File(docPath));
XWPFDocument document = new XWPFDocument(doc);
PdfOptions options = PdfOptions.create();
OutputStream out = new FileOutputStream(new File(pdfPath));
PdfConverter.getInstance().convert(document, out, options);
I want to convert my Word document to a PDF. The Word documents are created on Windows, and the code will run on a UNIX server. I need a way to convert Word (all extensions) to PDF with an inbuilt method using an external open source library such that if I ran it on Windows or UNIX, the PDF created should have the same font, font size, and number of pages.