How can I convert a Word document to PDF where the document contains various things, such as tables. When trying to use iText, the original document looks different to the converted PDF. Is there an open source API / library, rather than calling out to an executable, that I can use?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
It's already 2019, I can't believe still no easiest and conveniencest way to convert the most popular Micro$oft Word document to Adobe PDF format in Java world.
I almost tried every method the above answers mentioned, and I found the best and the only way can satisfy my requirement is by using OpenOffice or LibreOffice. Actually I am not exactly know the difference between them, seems both of them provide
soffice
command line.My requirement is:
First thing came in mind is
doc-to-pdf-converter
, but it lacks of maintenance, last update happened 4 years ago, I will not use a nobody-maintain-solution.Xdocreport
seems a promising choice, but it can only convertdocx
, but notdoc
binary file which is mandatory for me. Using Java to call OpenOffice API seems good, but too complicated for such a simple requirement.Finally I found the best solution: use OpenOffice command line to finish the job:
I always believe the shortest code is the best code (of course it should be understandable), that's it.
You can use JODConverter for this purpose. It can be used to convert documents between different office formats. such as:
More details about it can be found here: http://www.artofsolving.com/opensource/jodconverter
I haven't tried using it for MS Word, but I've had good success reading MS Excel documents using Apache POI - http://poi.apache.org/
Look into scripting OpenOffice.org to do the job for you.
I agree with posters listing OpenOffice as a high-fidelity import/export facility of word / pdf docs with a Java API and it also works across platforms. OpenOffice import/export filters are pretty powerful and preserve most formatting during conversion to various formats including PDF. Docmosis and JODReports value-add to make life easier than learning the OpenOffice API directly which can be challenging because of the style of the UNO api and the crash-related bugs.