PDF handling: Convert multiple .doc(x) files to separate .pdf files

Vassilis Chryssos
2 min readDec 5, 2020
An image to draw attention, in lack of a more appropriate graphic (Source: Created by the author)

It’s easy these days to convert a .docx file to .pdf by simply printing it as a .pdf file. But how can you print multiple .docx to separate .pdf files? Of course you can do it one-by-one, but if you have tens or hundreds of files it becomes tricky.

Here I describe how you can do this with one simple command in linux. You will need to work in the command line interface (CLI), but don’t be intimidated! It’s quite simple, really. For those of you who are comfortable using the command line use the following command in the folder where you have put your .docx files:

lowriter --headless --convert-to pdf *.docx

That’s it!

This command uses Libre Office’s engine to convert all of your .docx files to separate .pdf files. The --headless flag tells LibreOffice to just use the conversion engine instead of loading the whole LO environment.

It goes without saying, that you need to have LibreOffice installed in your computer!

When your files are in different folders

When your .docx files are located in many different folders it can be a pain to batch convert them to .pdf files. The trick here is to combine a couple of commands that will allow us to first find the files and then convert them to .pdf files in the folder of our choice.

We start by going to the parent folder where the sub-folders with our .docx files reside:

cd <path/to/folder>

and then we type the following command:

find . -type f -name “*.docx” -exec lowriter --convert-to pdf {} \;

The first part of this command finds in the current directory and all sub-directories (denoted by . in the command) all files (-type f) of type .docx (-name “*.docx”).

The second part of the command starts at -exec and it tells it to execute the lowriter command that we saw earlier for every file it locates. For a more thorough understanding of the -exec command you can view this excellent reply of the user Kusalananda at StackExchange.

--

--

Vassilis Chryssos

Open technologies enthusiast, pursuing sustainable social impact.