Options for converting Word documents to PDF

Fairly new using Lucee in production. Ran into an issue this week while converting uploaded documents to PDF. The problem is with converting Microsoft documents like Word .doc and .docx files. I found in the Lucee docs that these are not supported with the PDF extension.

What are you all using to convert Microsoft documents to PDF with Lucee? I’d like to be able to use something that integrates well with Lucee so we can continue with minimal (if any) code changes. Currently using the <cfdocument format="pdf" srcfile="worddoc.docx" filename="newdoc.pdf" overwrite=true fontembed="true"></cfdocument> tag to do these conversions where we have a Word document already and trying to convert them to PDF. Worked fine with Adobe CF.

Windows Server 2019
JavaVersion: 11.0.20
Apache Tomcat/9.0.78
Lucee stable

1 Like

My current approach to converting Word to PDF is to use LibreOffice via command line. The environment is Windows Server 2019, Java 11.0.22, Tomcat 9.0.84, Lucee Here is an example.

	<cfexecute name='C:\Program Files\LibreOffice\program\soffice.exe' arguments='--headless --convert-to pdf:writer_pdf_Export --outdir "C:\Temp\pdfdoc.pdf" "C:\docs\worddoc.docx"' timeOut='20' variable='cmdresult'></cfexecute>
	<cfset wait = Sleep(10000)>
	<cfcatch type="Any">
		<!---  --->

I would welcome a better method of converting Word to PDF.


My understanding of Maven is next to null, but this shows promise and Ill tinker around with it as time allows…

The package for Java to open a word file

The how To Use /

once you successfully get this working, you can get Lucee to output any content to a pdf

I haven’t tried this, but it looks promising as a method of converting DOCX to PDF using docx4j.

inputFileLocation = createObject("java", "java.io.FileInputStream").init(path_to_docx_file);

wordMLPackage = createObject("java", "org.docx4j.openpackaging.packages.WordprocessingMLPackage").load(inputFileLocation);

// Convert to PDF

outputFileLocation = createObject("java", "java.io.FileOutputStream").init(pdffile);

Docx4J.toPDF(wordMLPackage, outputFileLocation);


Thanks for the suggestion. Let me know how this goes for you if you try it out.

It will be a little while before I can focus back on this issue. Other priorities have taken precedence.