OpenOffice command line PDF creation

30,720

Solution 1

Art of Solving has also a very good API to perform the conversion in Java. It is a little slow but it is simple enough. This is how I use it:

        File inputFile = new File("C:\\oreyes\\hola.doc"); 
        File outputFile = new File("C:\\oreyes\\hola.pdf"); 
        OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
        try { 
            connection.connect(); 
        } catch(Exception e) {}

        DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
        converter.convert(inputFile, outputFile); 
        connection.disconnect(); 

You can create a jar with that and process it from the command line.

Solution 2

As of September 2012, LibreOffice can convert a document to PDF from the command line:

lowriter --headless --convert-to pdf yourfile.odt

It also has bulk conversion support:

lowriter --headless --convert-to pdf yourfiles*.odt

will convert all the files that match the pattern to the corresponding PDF file.

There must be no LibreOffice windows open when you run this command.

Solution 3

Though this question is a little old, here something for the purpose of documenting some common pitfalls with the LibreOffice solution:

  • If lowriter does not work for you because it ignores command line parameters and brings up the gui just try calling the libreoffice or loffice binaries:

    loffice --headless --convert-to pdf yourfile.odt

  • If you get this message

    Error: Please reverify input parameters...

    try running it as root (e.g. via sudo). This helped me on Ubuntu 12.04 LTS with LibreOffice 3 installed and may also be a reason why this conversion is not running on a webserver without proper configuration (Libreoffice --headless refuses to convert unless root, won't work from PHP script)

  • Also make sure that you do not have any other instances of LibreOffice running or it will just fail silently and do no conversion at all.

Solution 4

There is anytopdf. Haven't tried it myself.

Quoting...

anytopdf is a perl script that converts OpenOffice.org, Microsoft Office (Word DOC, Excel XLS), RTF, HTML, and other openoffice.org readable file formats to the PDF format. It will automatically install the supporting 'AnyToPDF' OpenOffice.org Basic macro library in the current user's OpenOffice.org configuration if it's not already present.

Dedicated to peace, love, understanding and respect for all beings.

Share:
30,720
Drejc
Author by

Drejc

Check out my git my previous endeavor DevScore or even LinkedIn

Updated on August 13, 2020

Comments

  • Drejc
    Drejc over 3 years

    I have some documentation written in OpenOffice, and I would like to include some of it as PDF files in the final build deliveries. I would like to do this with the automated build script.

    Is there a way to create a PDF file from OpenOffice with a command line command?