Qoppa’s library jOfficeConvert can convert both Microsoft Word documents and Excel spreadsheets to PDF with high fidelity and has support for many advanced Office features. The library can be run through command line to convert Office documents to PDF on Windows, Linux, Unix or macOS.
You will need to download Qoppa’s library jar, as well as the sample jar and make sure that you have Java installed on your server.
Follow the instructions below to do so:
- Download our library jar jofficeconvert.jar.
- Download our sample jar jocsamples.jar which contains many Java programs, including a class called WordCLI which is a command line interface to convert a Word document to PDF
- In the same directory, copy a Word document that you would like to convert, for instance a file called “input.docx”
- In the same directory, copy the font DroidSansFallbackFull.ttf that is set as fallback font in case a font specified in the Microsoft Word document is not found on the machine.
- Open a command prompt window and go to that directory
- Run the following command line:
java -Dqoppa.debug=true -cp jocsamples.jar;jofficeconvert.jar officeSamples.WordCLI -input input.docx -output output.pdf
- Usage: WordCLI -input -output -lickeyRequired arguments:
-input Input file name
-output Output file name
-fonts Path to a folder holding font files
-lickey License key to run in production mode - If you are running in a non GUI server, you will need to add the headless vm option to indicate that you want to run in headless mode
java -Djava.awt.headless=true -Dqoppa.debug=true -cp jocsamples.jar;jofficeconvert.jar officeSamples.WordCLI -input input.docx -output output.pdf
- That’s it! Your input.docx file was converted to a PDF file, called output.pdf.