OpenOffice command line PDF creation
Asked Answered
K

5

16

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?

Kahler answered 10/12, 2008 at 8:49 Comment(0)
A
12

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.

Aport answered 10/12, 2008 at 9:3 Comment(2)
Did same way as you describe, but specified OpenOfficeConnection officeConnection = new SocketOpenOfficeConnection( "my_local_vm_ip", 8100 );, but I get an error all the time. Exception in thread "main" com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException: conversion failed: could not load input documentMorisco
If you want to export with certain options (e.g. tagged PDF), do you first need to set them in OpenOffice or LibreOffice?Adal
T
31

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.

Tocology answered 20/9, 2012 at 8:25 Comment(10)
That's very neat. Do you know if there's a way to update a table of Contents before doing the conversion?Dunaway
I've managed to convert images, word documents, spreadsheets. Works like a charm.Retrograde
This solution is very solid but a bit slow. Just a little bit of info for anyone considering it, as of version 4.1.0.4, a fairly basic file is converting in 1800 ms.Dorotea
Strange, this is just opening a new document for me with Libreoffice in Ubuntu 13.10: both the --convert-to and the --headless args seem to be ignored. I'm trying to convert spreadsheets rather than docs, though.Midis
@Midis Are you using localc? I've just used the command on the LTS ubuntu (using localc instead of lowriter) and it worked flawlessy.Tocology
@Tocology Yep, I used localc. I suspect it's something wrong with my system and/or the latest LibreOffice. But unoconv (below) from the U13.10 repository worked perfectly.Midis
Since this is not documented here yet: If this command line call fails with 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 if it ignores the --headless parameter try calling loffice or libreoffice instead of lowriter.Maiamaiah
@PieterHintjens You can define a global marco to update the TOC before doing the conversion as shown in ask.libreoffice.org/en/question/46586/…. You might want to start in headless mode and add starDesktop.terminate() in the macro to close LibreOffice once the conversion is complete.Maddening
If you want to export with certain options (e.g. tagged PDF), do you first need to set them in OpenOffice or LibreOffice? Or is there a command line argument for options like this?Adal
--convert-to already implies --headless, at least in my case (version 6.0.7.3 00m0(Build:3)).Spectra
S
16

There is a great tool called "unoconv", it was in my Ubuntu repository. It converts ODF, .ods, ... to PDF and I think to other formats too.

I also could convert PowerPoint files to PDF.

Shalna answered 16/5, 2009 at 11:32 Comment(0)
A
12

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.

Aport answered 10/12, 2008 at 9:3 Comment(2)
Did same way as you describe, but specified OpenOfficeConnection officeConnection = new SocketOpenOfficeConnection( "my_local_vm_ip", 8100 );, but I get an error all the time. Exception in thread "main" com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException: conversion failed: could not load input documentMorisco
If you want to export with certain options (e.g. tagged PDF), do you first need to set them in OpenOffice or LibreOffice?Adal
M
2

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.

Maiamaiah answered 19/5, 2014 at 11:46 Comment(0)
C
1

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.

Compose answered 26/7, 2010 at 16:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.