开发者

Library that can convert Word documents doc(x) to pdf

I'm working on a software that should be able to automatically convert Word documents to pdfs. Is there any library that supports Java preferably that can achieve this? It can be either free or commercial, it doesn't mat开发者_开发知识库ter.

Thanks


I haven't used it, but you could try JODConverter


Most people on StackOverflow recommend Apache POI which can convert most Microsoft Office formats into PDF and vice-versa. It's open-source.


@BoffinbraiN, POI doesn't do much to help you to convert Office documents to PDF.

Apache FOP can be used to do this, but if you want to use FOP, first you need to convert the Office document to XSL-FO.

Here, docx4j can help, as it generates the XSL-FO, and uses FOP 1.0 to create the PDF.

Assuming OutputStream os and a loaded WordprocessingMLPackage wordMLPackage:

PdfConversion c = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(wordMLPackage);
c.output(os);

See further the docx4j sample CreatePdf.java.


There are a couple of open source solutions available, but none keep the formatting of the source document completely.

Give the Muhimbi PDF Converter Services a look. It installs in your environment as a scalable and robust Windows Service and has specifically been designed for use from server based applications such as Java and ASP.NET.

It comes with a friendly web services based interface that allows it to be used from most modern environments such as Java and .NET. It supports all common as well as some not so common file formats. Watermarking and PDF Security is included as well.

Disclaimer, I have worked on this product so the usual disclaimers apply. Having said that, it works great.


docx2pdf is a command line tool and python library that can achieve this on macOS and Windows. From Java, you should be able to call the tool using the command line. Internally, this python library calls an AppleScript from the command line in order to get it to work on macOS.

https://github.com/AlJohri/docx2pdf/

The benefit to this approach is that it uses Word's own APIs to create a pixel perfect conversion.

Disclaimer: I wrote this tool.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜