How to convert Microsoft Office *.docx files to PDF using Linux in command-line

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.

How to convert *.docx files (Microsoft Office 2007) online for free

Sometimes you might have no choice except to open Microsoft Office 2007 (*.docx) files that you’ve just received in your email. The problem is, you do not have any other application that support Office 2007 format.

Here’s an easy way to (kinda) solve that problem, you can convert Microsoft Office 2007 files online, using Google Docs.

Google Docs Logo

The steps are easy, you need to login into your Google Docs account, then upload the Office 2007 files. After that, you can choose the “Download file as” option to convert the file to your favorite document format (typically OpenDocument or older *.doc Microsoft Office word document).

Bear in mind that the conversion is not 100% perfect and there will be parts of document that won’t look exactly as the original ones.

How to convert OpenXML docx files to OpenDocument odf in Windows and vice versa

This guide might be a little different from the others because I write this for the Windows users. Here’s how to convert Microsoft OpenXML docx files to odf OpenDocument files (and vice versa) in Windows using only commandline :

  • First, make sure you downloaded odf-converter tool and copy it to appropriate folder.
  • Convert the files(s) using this command line :
    odfconverter /I filename.pptx
    and the tool will perform the conversion effortlessly.
  • You can use this command to convert multiple files :
    odfconverter /BATCH-DOCX /I c:\newfiles\

    replace /BATCH-DOCX with /BATCH-PPTX, /BATCH-XLSX, /BATCH-ODF, /BATCH-ODP if necessary.

Odfconverter also supports converting Open Document files (ODF, ODP, ODT) to OpenXML files (PPTX,DOCX,XLSX) making it a handy tool to use.

Why odfconverter?
Odfconverter is a (relatively) small and compact standalone tool for converting Office 2007 files to their OpenDocument counterpart. The convenient batch mode conversion makes it attractive tool to use when converting multiple files between the two formats.

The only downside with this converter is that it does not convert mathematical formula pretty well compared to other features.

[Source OOOninja]