2

I am using Java and xdocreport to edit .odt files (template) and save it as odt. Everything working fine but when I try to convert the odt to pdf I get this error:

ODFConverterException: java.lang.ClassCastException: Insertion of illegal Element: 12

This error is caused by a textbox in my odt source file.

From odt to odt every thing works fine it preserve my textbox.

So I tried to change my dependencies in my pom to the newest version. Now I don't have this problem an more but it generates a pdf file without the text box.

I really need a pdf with the textbox, on the internet I found that ODFConvertor is limited.

public void generate(ctModel ctmodel) throws Exception {

    final InputStream in =new FileInputStream(new File("C:\\Users\\A_PC\\Desktop\\AB\\abs-templateGenerator\\src\\main\\resources\\ODM.odt"));
    final IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, TemplateEngineKind.Velocity);

    // 2) Create context Java model and add model
    final IContext context = report.createContext();

    context.put("ct",ctmodel);

    OutputStream out = new FileOutputStream(new File("C:\\Users\\ANDRICE_PC\\Desktop\\ANDRICE-BRAIN\\abs-templateGenerator\\src\\main\\resources\\ODM_final.odt"));
    report.process(context, out);


    //generate PDF
    InputStream inPdf= new FileInputStream(new File("cdi_final.odt"));
    OdfTextDocument document = OdfTextDocument.loadDocument(inPdf);


    PdfOptions options = PdfOptions.create().fontEncoding("");

    OutputStream outPdf = new FileOutputStream(new File("cdi_final.pdf"));
    PdfConverter.getInstance().convert(document, outPdf, options);
}

my pom :

<dependency>
    <groupId>fr.opensagres.xdocreport</groupId>
    <artifactId>fr.opensagres.xdocreport.document.odt</artifactId>
    <version>1.0.6</version>
</dependency>

<dependency>
    <groupId>fr.opensagres.xdocreport</groupId>
    <artifactId>fr.opensagres.xdocreport.converter.odt.odfdom</artifactId>
    <version>1.0.6</version>
</dependency>

<dependency>
    <groupId>fr.opensagres.xdocreport</groupId>
    <artifactId>fr.opensagres.xdocreport.template.velocity</artifactId>
    <version>1.0.6</version>
</dependency>

Can someone give a solution to preserve my textbox in the pdf or another solution to convert my odt to pdf with my text boxes?

Amedee Van Gasse
  • 7,280
  • 5
  • 55
  • 101
sesh-777
  • 23
  • 1
  • 6

0 Answers0