Java: JODConverter 3.x Getting Started

April 9th, 2009 by jeremychone

Requirements:

  • OpenOffice installed and OpenOffice started (e.g., OpenOffice in the system tray on Windows)
  • Java

Quick steps to test:

  1. Download the latest JODConverter 3.x from google code.
  2. Unzip the jar file
  3. Do a quick test:
    java -jar lib/jodconverter-${version}.jar test.odt test.pdf
  4. you should see something like
    C:\apps\jodconverter-3.0-beta-1>java -jar lib/jodconverter-3.0-beta-1.jar test.odt test.pdf
    
    Apr 9, 2009 12:56:42 PM net.sf.jodconverter.office.OfficeProcess start
    INFO: starting process with acceptString 'socket,host=127.0.0.1,port=8100' and
    profileDir 'C:\Users\JEREMY~1\AppData\Local\Temp\.jodconverter_socket_host-127.0.0.1_port-8100'
    Apr 9, 2009 12:56:42 PM net.sf.jodconverter.office.OfficeProcess start
    INFO: started process; pid -1
    Apr 9, 2009 12:56:47 PM net.sf.jodconverter.office.OfficeConnection connect
    INFO: connected: 'socket,host=127.0.0.1,port=8100'
    Apr 9, 2009 12:56:52 PM net.sf.jodconverter.office.OfficeConnection$1 disposing
    INFO: disconnected: 'socket,host=127.0.0.1,port=8100'
    Apr 9, 2009 12:56:53 PM net.sf.jodconverter.office.ManagedOfficeProcess doEnsureProcessExited
    INFO: process exited with code 0

Note: As you can see it works because it assumes that OpenOffice listen to the port 8100, which happen to be the case (how lucky!).

In a Java (Server) App:

  1. Copy the following .jar files in your webapp lib directory
    lib/jodconverter-3.0-beta-1.jar
    lib/juh-3.0.0.jar
    lib/jurt-3.0.0.jar
    lib/ridl-3.0.0.jar
    lib/unoil-3.0.0.jar
  2. Use the following code snippet:
    OfficeManager officeManager = new ManagedProcessOfficeManager();
    officeManager.start();
    
    OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
    converter.convert(sourceFile,targetFile);
    
    officeManager.stop();

Best Practice (from JODConverter group)

  1. OfficeManager instance can and should be shared across all
    threads
    . It should typically be started when your webapp starts, and
    stopped when the webapp stops. It can be e.g. a singleton, or a Spring
    bean, or other equivalent approach of your choice.
  2. The OfficeDocumentConverter instance can also be shared, or you can
    create a different instance per thread. It doesn’t really matter,
    since all conversions will be delegated to the OfficeManager anyway.

See Also

7 Responses to “Java: JODConverter 3.x Getting Started”

  1. Laurent Says:

    I gave a try to JODConverter 3 -
    perfect for PDF-1.4
    i’d like to convert an ODT to PDF/A - tried with 2.x release of jodconverter, playing on OOo “SelectPdfVersion” property (set to 1) has no effect >> i get a PDF 1.4 doc in output.
    That’s why i wanted to try jodconverter 3 >> i try to play on outputFormat.setStoreProperties (still no effect)
    Any idea? Thanks

  2. jeremychone Says:

    @Laurent, nop, sorry, I do not use it to generate PDF/A.

  3. Shervin Asgari Says:

    Hmm thats strange.
    SelectPdfVersion set to 1 should have worked.

    PDFXNONE = 0
    PDFX1A2001 = 1
    PDFX32002 = 2
    PDFA1A = 3
    PDFA1B = 4

    Maybe you can try with other stuff. I am trying to convert to PDF/A myself and I am not sure if I successfully do this.

    Please let me know Laurent if you manage to do this correctly.

  4. Shervin Asgari Says:

    I finally figured it out.
    My problem was that I had an extra space in the pdfOption definition. Other than that, SelectPdfVersion 1 worked just fine.

    Remember also to set DocumentFormat.TEXT

  5. Michael Greifeneder Says:

    In order to generate PDF/A with JODConverter 3.x I changed the definition of PDF in constructor of DefaultDocumentFormatRegistry:

    DocumentFormat pdf = new DocumentFormat(”Portable Document Format”, “pdf”, “application/pdf”);
    Map map = new HashMap();
    map.put(”FilterName”, “writer_pdf_Export”);
    PropertyValue[] aFilterData = new PropertyValue[1];
    aFilterData[0] = new PropertyValue();
    aFilterData[0].Name = “SelectPdfVersion”;
    aFilterData[0].Value = 1;
    map.put(”FilterData”, aFilterData);
    pdf.setStoreProperties(DocumentFamily.TEXT, map);

  6. Kay Ramme of Sun has created “ODF@WWW,” an ODF Wiki « Wave A Dead Chicken Says:

    [...] http://www.bitsandpix.com/entry/java-jodconverter-3x-getting-started/ [...]

  7. Avatar Oyunları Says:

    @jeremy, I gave a try to JODConverter 3 -

Leave a Reply