Convert Documents With LibreOffice Headless
Convert Documents With LibreOffice Headless
Libreoffice is a wonderful office suite, for Open Source shops, it’s the defacto standard, not only because it’s a good graphical office suite, the licensing is free, but because it can ALSO do headless, non-graphical document conversion. Let’s walk through the process.
Install Libreoffice Headless

now we have told Linux we want headless libreoffice, we just need to install the office suite packages:

The next thing to do is to look at man soffice, there is a whole section on document conversion.
–convert-to output_file_extension[:output_filter_name] [–outdir output_dir] file…
Batch converts files. If –outdir is not specified then the current working directory is used as the output directory for
the converted files.
Examples:
–convert-to pdf *.doc
Converts all .doc files to PDFs.
–convert-to pdf:writer_pdf_Export –outdir /home/user *.doc
Converts all .doc files to PDFs using the settings in the Writer PDF export dialog and saving them in /home/user.
as you can see, there is a number of options such as converting pdf to .doc, convert pdf to libreoffice writer document, or converting documents to pdf.
Let’s try it:
** note you can specify optionally –headless if you have a graphical system, but we specifically installed LibreOffice headless, so this is not necessary, it’s already assuming that.
Convert .doc/docx to PDF:
[user@build]~% soffice –headless –convert-to pdf test_doc.docx
convert /home/user/test_doc.docx -> /home/user/test_doc.pdf using writer_pdf_Export
[user@build]~%
Bam, our .docx documente was converted to PDF!
Convert PDF to .doc/.docx:
[user@build]~% soffice –headless –convert-to docx test_doc.pdf
convert /home/user/test_doc.pdf -> /home/user/test_doc.docx using
[user@build]~%
Bam, our .pdf is now a .docx
Text to PDF:
[user@build]~% soffice –headless –convert-to pdf test.txt
convert /home/user/test.txt -> /home/user/test.pdf using writer_pdf_Export
[user@build]~%
That’s it, you have mastered the basics of LibreOffice Document Conversion, Happy Converting!
Hosted Linux Servers at www.zwiegnet.com/go
Related guides: Developing Applications for RHEL/CentOS | Build RPM From Source
