Docx is a popular file format for documents created using Microsoft Word. But often you may need to convert docx files to pdf, which is also widely popular. If you have Microsoft Word installed on your system, you can easily choose this option from File Menu. But if you are using Linux or don’t have MS Word installed on your system then you may need to use workarounds for it. In this article, we will learn how to convert docx to pdf in Linux. You can use these commands on almost every Linux distribution, for both .doc as well as .docx files.
How to Convert Docx to PDF in Linux
In order to convert docx to pdf documents, you will need to have LibreOffice or OpenOffice installed on your system. These are free alternatives to Microsoft Office and allow you to work with docx files. We have assumed that you have either of them already installed on your system.
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.
$ sudo apt-get install cups-pdf
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”.
Then run the following command, using oowriter, to convert your doc file to pdf using OpenOffice
$ oowriter -pt pdf your_word_file.docx
Here is an example to convert file /home/ubuntu/test.docx to test.pdf.
$ oowriter -pt pdf /home/ubuntu/test.docx
After you run the above command, you will find your PDF file at ~/PDF.
If you are using LibreOffice, you need to run the following command using lowriter.
$ lowriter --convert-to pdf your_word_file.docx
Here is an example command to convert /home/ubuntu/test.docx file.
$ lowriter --convert-to pdf /home/ubuntu/test.docx
If you are running LibreOffice, you can also use swriter instead of lowriter as shown below.
swriter -convert-to pdf:writer_pdf_Export /home/ubuntu/test.docx OR writer -convert-to pdf:writer_pdf_Export /home/ubuntu/test.docx
Please note, you can use the above commands to convert .doc files to pdf also.
Alternatively, you can also use Ghostscript & tetex-extra for this purpose. Run the following command to install the packages.
$ sudo apt-get install wv tetex-extra ghostscript
If tetex-extra package is not available for your Linux distribution, install the following packages instead.
$ sudo apt-get install wv texlive-base texlive-latex-base ghostscript
Here is the command to convert docx file to pdf.
$ wvPDF /path/to/docx /path/to/pdf
Here is an example command to convert /home/ubuntu/test.docx to /home/ubuntu/test.pdf.
$ wvPDF /home/ubuntu/test.docx /home/ubuntu/test.pdf
In this article, we have learnt how to convert docx to pdf in Linux. Typically PDF conversion is required in organizations and teams who use docx files to create the document and convert them into PDFs to share them with others. If you just want to convert a single docx or doc file to PDF you can use an online converter like smallpdf. But if you want to convert many docx/doc files to PDF then you will need to use the above mentioned commands. They are also useful if you want to programmatically convert docx files to PDF or if you want to offer ‘export to PDF’ feature in your application.
Also read:
How to Remove Yum Repository
How to Remove Repository in Ubuntu
How to Deny SSH for Users or Groups
How to Batch Convert PNG to JPG in Linux
How to Convert Webp to Gif in Linux
Related posts:
Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.