OpenOffice command line PDF creation

大兔子大兔子 提交于 2019-11-28 06:30:15
OscarRyz

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.

Eineki

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.

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!