Converting Open office format (ODT & ODS) to PDF in Java

Hi,
I have been evaluating GroupDocs conversion with converting some of the basic Open Office format documents to PDF.
When I try to convert .odt or .ods files to PDF I get below exception. I tried with creating very basic odt and ods documents. However all MS Office formats work correctly.
This happens with the version 17.3.0.
These are essential document formats that I want to support in my upcoming projects.

Exception in thread “main” class com.groupdocs.conversion.internal.c.a.s.kt: Not a Open Office presentation
com.groupdocs.conversion.internal.c.a.s.uh.a(Unknown Source)
com.groupdocs.conversion.internal.c.a.s.kB.(Unknown Source)
com.groupdocs.conversion.internal.c.a.s.kA.h(Unknown Source)
com.groupdocs.conversion.internal.c.a.s.kA.H(Unknown Source)
com.groupdocs.foundation.a.b.c(Unknown Source)
com.groupdocs.foundation.a.b.a(Unknown Source)
com.groupdocs.foundation.a.b.e(Unknown Source)
com.groupdocs.conversion.domain.b.q(Unknown Source)
com.groupdocs.conversion.domain.b.a(Unknown Source)
com.groupdocs.conversion.handler.ConversionHandler.b(Unknown Source)
com.groupdocs.conversion.handler.ConversionHandler.b(Unknown Source)
com.groupdocs.conversion.handler.ConversionHandler.convert(Unknown Source)
com.Processor.convertToHtmlAsStream(Processor.java:46)
com.Main.main(Main.java:16)
at com.groupdocs.conversion.internal.c.a.s.uh.a(Unknown Source)
at com.groupdocs.conversion.internal.c.a.s.kB.(Unknown Source)
at com.groupdocs.conversion.internal.c.a.s.kA.h(Unknown Source)
at com.groupdocs.conversion.internal.c.a.s.kA.H(Unknown Source)
at com.groupdocs.foundation.a.b.c(Unknown Source)
at com.groupdocs.foundation.a.b.a(Unknown Source)
at com.groupdocs.foundation.a.b.e(Unknown Source)
at com.groupdocs.conversion.domain.b.q(Unknown Source)
at com.groupdocs.conversion.domain.b.a(Unknown Source)
at com.groupdocs.conversion.handler.ConversionHandler.b(Unknown Source)
at com.groupdocs.conversion.handler.ConversionHandler.b(Unknown Source)
at com.groupdocs.conversion.handler.ConversionHandler.convert(Unknown Source)
at com.Processor.convertToHtmlAsStream(Processor.java:46)
at com.Main.main(Main.java:16)

@amitph,

Thanks for your inquiry. We are not able to reproduce this issue at our end. Please find the sample OpenOffice documents and output files. OpenOffice to PDF.zip (46.5 KB)
In order to further investigate your issue, we need the problematic files. Can you please share the ODT and ODS files you are trying to convert?

Thanks for replying back.
I tried both of the files (odt & ods) in your zip and got the same exception that I got above.
I am creating a FileInputStream and passing it to the ‘convert’ method as belows.

Please let me know if I am doing the conversions incorrectly.

public void convertToPdf(FileInputStream fis) throws Exception {

    PdfSaveOptions saveOption = new PdfSaveOptions();
    saveOption.setConvertFileType(PdfSaveOptions.PdfFileType.PDF);
    saveOption.setOutputType(OutputType.String);
    ConversionHandler conversionHandler = new ConversionHandler(Utilities.getConfiguration());

    String path = conversionHandler.<String>convert(fis, saveOption);
    System.out.println(path);
}

@amitph,

Thanks for sharing the details. We reproduced this issue at our end. However, with few amendments in the code we can resolve it. Please utilize the code given below in your method (convertToPDF) and share your experience.

String storagePath = "D:/Storage";
String outputPath = "D:/ConvertedStorage";
// Setup Conversion configuration
ConversionConfig conversionConfig = new ConversionConfig();
conversionConfig.setStoragePath(storagePath);
conversionConfig.setOutputPath(outputPath);
// Instantiating the conversion handler
ConversionHandler conversionHandler = new ConversionHandler(conversionConfig);
PdfSaveOptions saveOption = new PdfSaveOptions();
saveOption.setOutputType(OutputType.String);
String guid = "D:/Storage/odt.odt";
FileStream fileStream = new FileStream(guid, FileMode.Open, FileAccess.Read);
// Convert document
String convertedDocumentPath = conversionHandler.<String>convert(fileStream.toInputStream(), guid, saveOption);

@atirtahir3
Thanks for the reply.
The solution you provided worked for me.
The only essential thing I figured here is convert method explicitly needs the name of the file. Looks like it identifies the type of file in the input stream.
Let me know, if I am wrong.

@amitph,

We’re pleased to hear that. Yes, file name is required for the convert method (it identifies file type) in order to perform proper conversation.

1 Like

Using file extension for filetype is not reliable as not everyone honors filetype naming. The method that we used with 16.10.1 was to read all files as input streams then using ConversionHandler.getSaveOptions(inputStream). We’re getting a number of the same errors related to Open Office slides. This seems like a regression or deprecation without notice. What is the plan to correct this?

Following up with data to support that this is a serious regression in 17.04:
Not a Open Office presentation Before Upgrade After Upgrade

Monday 9-11-2017 0 9-25-2017 8350
Tuesday 9-12-2017 0 9-26-2017 7524
Wednesday 9-13-2017 0 9-27-2017 6884
Thursday 9-14-2017 0 9-28-2017 7806
Friday 9-15-2017 0 9-29-2017 5672
Saturday 9-16-2017 0 9-30-2017 3782
Sunday 9-17-2017 0 10-1-2017 7592

We went from no occurrences of this exception to thousands per day upon upgrade. We were previously processing roughly the same volume.

@jgorr,

We’ve logged this issue in our internal issue tracking system with ID:CONVERSIONJAVA-442. As we get any update from the concerned team, we’ll apprise you.

Great, thank you. One thing that I’ve noticed with this error is that it’s often being thrown for files that are Libre/Open Office Writer(odt) docs. We’re not using filename conversion calls, rather we are using streams. Hope this info helps.

@jgorr,

Thanks for the further details. We’ve shared your scenario with concerned team and they are investigating the issue. As we get any update from them, we’ll notify you.