This advanced tutorial would help you to batch convert Writer documents (docx, odf, odt) to PDF using the free LibreOffice office suite.
Converting multiple Microsoft Word *.docx, *.doc OR open document format files – *.odf, *.odt files to PDF at once can be tricky. Especially, if you are dealing with hundreds of files and need to convert them into PDFs in batches. You can convert hundreds, and thousands of files to PDF using the free LibreOffice office suite.
Table of Contents
Steps to convert document files to PDF
Note: The steps are different for Windows and Linux. Follow accordingly.
Convert a single file
- In Windows systems (tested in Windows 10), open the command prompt or Press Windows+R and type ‘cmd’ and press enter.
- In the command prompt, type the below command:
"C:\Program Files (x86)\LibreOffice 5\program\swriter.exe" --headless --convert-to pdf Untitled1.odt
- In Linux systems, including Ubuntu as well, open the terminal (CTRL+ALT+T) and run the below command:
lowriter --headless --convert-to pdf Untitled1.odt
Note:
- By default, the installation directory of LibreOffice is in the above path for Windows 10 & Windows 11. If you have installed it on a different path, change accordingly.
- The document Untitled1.odt would be converted to Untitled1.pdf in the same directory as the odt.
- If you have a docx Word file, you can specify the same in place of Untitled1.odt.
Convert multiple files via batch mode
- Converting multiple files is tricky due to different ways of handling wildcard characters in Windows.
- Open the command prompt or Press Windows+R and type ‘cmd’ – enter.
- In the command prompt, type three lines precisely as below. Enter each line and press enter.
- You can change *.odt in the first line to *.docx for Word files.
For %f in (*.odt) do ( "C:\Program Files (x86)\LibreOffice 5\program\swriter.exe" --headless --convert-to pdf %f )
- In Linux systems, including Ubuntu as well, open the terminal (CTRL+ALT+T) and run the below commands:
lowriter --headless --convert-to pdf *.odt
- Wait till the above command executes. It takes some time to convert each document. On average, it takes approximately 20 to 30 seconds per file (2 pages) on Windows 10.
- After conversion, check the folder of the source document for converted PDF files.
Additional Options for batch conversation via command line (LibreOffice 7.4 and above)
LibreOffice 7.4 and above offers the following options for better control while using the command line. Here are some examples.
- Skip the first page while converting a Draw document to PDF.
soffice --convert-to 'pdf:draw_pdf_Export:{"PageRange":{"type":"string","value":"2-"}}' test.odg
- Add a watermark in the PDF
soffice --convert-to 'pdf:draw_pdf_Export:{"TiledWatermark":{"type":"string","value":"draft"}}' test.odg
- Add a password to the PDF document while converting. Change the below “secret” string to your password.
soffice --convert-to 'pdf:draw_pdf_Export:{"EncryptFile":{"type":"boolean","value":"true"},"DocumentOpenPassword":{"type":"string","value":"secret"}}' test.odg
- Change the PDF writer version of your output PDF
soffice --convert-to 'pdf:draw_pdf_Export:{"SelectPdfVersion":{"type":"long","value":"15"}}' test.odg
- Sign the PDF.
soffice --convert-to 'pdf:draw_pdf_Export:{"SignPDF":{"type":"boolean","value":"true"},"SignCertificateSubjectName":{"type":"string","value":"CN=…"}}' test.odg
Conclusion
The above methods explain how you can easily batch convert Writer documents (docx, odt) to pdf using free LibreOffice Writer. You do not need any other software, installers, or pdf printers for this work.
Drop a comment below if this article helped you or if you have any questions.
Reference
--convert-to OutputFileExtension[:OutputFilterName] [--outdir output_dir] [--convert-images-to] Batch convert files (implies --headless). If --outdir isn't specified, then current working directory is used as output_dir. If --convert-images-to is given, its parameter is taken as the target MIME format for *all* images written to the output format. If --convert-to is used more than once, the last value of OutputFileExtension [:OutputFilterName] is effective. If --outdir is used more than once, only its last value is effective. For example: --convert-to pdf *.odt --convert-to epub *.doc --convert-to pdf:writer_pdf_Export --outdir /home/user *.doc --convert-to "html:XHTML Writer File:UTF8" *.doc --convert-to "txt:Text (encoded):UTF8" *.doc