Here’s how to convert Microsoft Office *.docx files to PDF using Linux in Command Line.
This trick can also be used together with other documents files supported by LibreOffice
First make sure you’ve installed the latest version of LibreOffice for use in command line environment.
Assuming the user is ‘example’ and the filename to convert is ‘doc.pdf’.
libreoffice --headless -convert-to pdf --outdir /home/example/ /home/example/doc.docx
The conversion can also be adapted to PHP or Python using their respective shell_exec or subprocess directive.