Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any GNU/Linux command line utility that converts .doc(x) files to .pdf? [closed]

Tags:

pdf

People also ask

How do I convert a docx to pdf in Linux?

If you have either of the above mentioned software installed on your system, open terminal and run the following command to install cups-pdf utility. Then navigate to System > Administration > Printing in Linux system. Create a new printer, set it as a PDF file printer, and name it as “pdf”.

How do I convert a Linux file to pdf?

Go to the /etc/ImageMagick-6/ directory and open the policy. xml file in your favorite editor. Run the “convert” command again and list the directory to find a new pdf file.


Unfortunately there are no Linux-based guaranteed 1-to-1 convertors for Word (doc/docx) to PDF. This is because Word, a Microsoft product, uses a proprietary format that changes slightly with every release. As it was not traditionally a publicly documented format and Microsoft does not port Word/Office to Linux (nor ever will) then you must rely upon reverse engineered third party tools for older formats (doc) and proper interpretation of the Office Open XML format by third party developers.

We found the best open source solution is LibreOffice (which was forked from OpenOffice.org, which itself was called Star Office before it was open sourced). It is much more actively developed than AbiWord, as another answer suggested.

The usage from the command line is simple and well documented with plenty of examples:

soffice --headless --convert-to pdf filename.doc

Or also you can use libreoffice instead of soffice on newer versions.


There is also Pandoc.

Pandoc, mainly known for its Markdown-capable processing goodness (for outputting HTML, LaTeX, PDF, EPUB and what-not) in recent months has gained a rather well-working capability to process DOCX input files.
(NOTE: Pandoc only works for DOCX, not for DOC files.)

For its PDF output to work, it requires a working LaTeX installation (with either or all of pdflatex, lualatex and xelatex included). In this case the following simple command should work:

pandoc -o output.pdf -f docx input.docx

Note however, that the output layout and font styles now will not look at all similar to what it would look if you exported the DOCX from Word to PDF. It will be using the styles of a default LaTeX document.

You can influence the output style of the LaTeX-generated PDF by using a custom template file like this...

pandoc                              \
  -o output.pdf                     \
  -f docx                           \
 --template=my-latex-template.tmplt \
   input.docx

...but this is a feature more for Pandoc/LaTeX experts to use than for beginners.