Libreoffice - command line conversion to other formats

By xngo on June 19, 2019

From the user interface, Libreoffice can save to different type of document formats: PDF, CSV, HTML, MS Excel, MS Word, etc. But do you know that you can do the same using the command line. This is very useful when you have to repeatedly convert the same document to different formats or you have to convert a lot of documents. I will show you how to do it below.

Writer

# Convert to PDF: It will output myfile.pdf
libreoffice --headless --convert-to pdf mydoc.odt
 
# Convert to MS Word: It will output myfile.doc
libreoffice --headless --convert-to doc mydoc.odt
 
# Convert to new version of MS Word: It will output myfile.docx
libreoffice --headless --convert-to docx mydoc.odt
 
# Convert to HTML: It will output myfile.html
libreoffice --headless --convert-to html mydoc.odt
 
# Convert to EPUB e-book: It will output myfile.html
libreoffice --headless --convert-to epub mydoc.odt
  • --headless: Use Libreoffice without the user interface.
  • --convert-to: Convert to the desired format. Simply add the extension of the type of file that you want to export to.
  • mydoc.odt: Your input document.

Calc

# Convert to PDF: It will output mysheet.pdf
libreoffice --headless --convert-to pdf mysheet.ods
 
# Convert to MS Excel: It will output mysheet.xls
libreoffice --headless --convert-to xls mysheet.ods
 
# Convert to new version of MS Excel: It will output mysheet.xlsx
libreoffice --headless --convert-to xlsx mysheet.ods
 
# Convert to HTML: It will output mysheet.html
libreoffice --headless --convert-to html mysheet.ods
 
# Convert to CSV: It will output mysheet.csv
libreoffice --headless --convert-to html mysheet.ods

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.