16

To start to work with XDocReport I want to convert ODT to PDF.

All my application is OSGi. So I install the following bundles:

fr.opensagres.xdocreport.converter-1.0.5.jar
fr.opensagres.xdocreport.core-1.0.5.jar
fr.opensagres.xdocreport.document-1.0.5.jar
fr.opensagres.xdocreport.itext.extension-1.0.5.jar
fr.opensagres.xdocreport.template-1.0.5.jar

Besides in class path I have itext-4.2.1.jar (it is not OSGi bundle) and I export the following packages:

  <package name="com.lowagie.text"/>
  <package name="com.lowagie.text.factories"/>
  <package name="com.lowagie.text.pdf"/>
  <package name="com.lowagie.text.pdf.draw"/>

However, I don't get converter using the following code:

Options options = Options.getFrom(DocumentKind.ODT).to(ConverterTypeTo.PDF);
IConverter converter = ConverterRegistry.getRegistry().getConverter(options);
in = new FileInputStream(new File("/Temp/Test1.odt"));
OutputStream out = new FileOutputStream(new File("/Temp/Test1.pdf"));
converter.convert(in, out, options); //HERE I GET NullPointerException - converter is null.

Trying to solve this problem I added the following bundles:

org.odftoolkit.odfdom.converter.core-1.0.5.jar
org.odftoolkit.odfdom.converter.pdf-1.0.5.jar

However, I get:

org.osgi.framework.BundleException: Unresolved constraint in bundle org.odftoolkit.odfdom.converter.core [43]: Unable to resolve 43.0: missing requirement [43.0] osgi.wiring.package; (osgi.wiring.package=org.odftoolkit.odfdom.dom)

To solve problem with org.odftoolkit.odfdom.dom I added odfdom-java-0.8.7.jar to classpath (it is also not OSGi) and export the following package:

   <package name="org.odftoolkit.odfdom.doc"/>
   <package name="org.odftoolkit.odfdom.dom"/>
   <package name="org.odftoolkit.odfdom.dom.element.draw"/>
   <package name="org.odftoolkit.odfdom.dom.element.office"/>
   <package name="org.odftoolkit.odfdom.dom.element.style"/>
   <package name="org.odftoolkit.odfdom.dom.element.table"/>
   <package name="org.odftoolkit.odfdom.dom.style"/>
   <package name="org.odftoolkit.odfdom.incubator.doc.office"/>
   <package name="org.odftoolkit.odfdom.incubator.doc.style"/>
   <package name="org.odftoolkit.odfdom.pkg"/>
   <package name="org.odftoolkit.odfdom.dom.attribute.fo"/>
   <package name="org.odftoolkit.odfdom.dom.attribute.style"/>
   <package name="org.odftoolkit.odfdom.dom.attribute.table"/>
   <package name="org.odftoolkit.odfdom.dom.element"/>
   <package name="org.odftoolkit.odfdom.dom.element.svg"/>
   <package name="org.odftoolkit.odfdom.dom.element.text"/>

However it didn't help and I still get NullPointerException.

These are my questions:

  1. What is the reason I get null converter and how to fix it?
  2. What library does XDocReport use itext or odfdom for converting?
BartoszKP
  • 34,786
  • 15
  • 102
  • 130
Pavel_K
  • 10,748
  • 13
  • 73
  • 186
  • 9
    Please take your discussion over the tags on this question somewhere else. Here - http://meta.stackoverflow.com/questions/298601/must-using-stackoverflow-tags-be-approved-by-the-name-rights-holders - is a good place. – ChrisF Jul 05 '15 at 19:53
  • The package to export should be org.odftoolkit.odfdom.dom and not org.odftoolkit.odfdom.doc, no? – Angelo Jul 06 '15 at 05:47
  • XDocReport supports itext 2.1.7 or itext . I don't know if itext-4.2.1.jar can be used. I suggest you that you try without OSGi context. – Angelo Jul 06 '15 at 06:18
  • @Angelo Replacing 4.2.1 with 2.1.7 didn't help. – Pavel_K Jul 06 '15 at 06:23
  • Have you checked that org.odftoolkit.odfdom.converter.pdf is started? Have you some stacktrace errros? – Angelo Jul 06 '15 at 07:28
  • @Angelo Yes, it is started. I started all the bundles I named in my question. They all started and I don't get any package exception or warning. – Pavel_K Jul 06 '15 at 10:37

1 Answers1

2

What I usually do is to take the library, that wasn't an OSGi bundle, and wrapped it. A good tutorial on how to do this in eclipse is Lars Vogel's tutorial: How to create Eclipse plugins from jars.

Than export the project as a jar file by following Creating a jar File in Eclipse tutorial, and use this in your project.

Now you should have all your dependencies resolved. Extra steps are needed in case you have dynamic class loading too.