генерация pdf файла из odt с использованием java и xdocreport - PullRequest
0 голосов
/ 17 апреля 2019

Я использую Java и xdocreport для редактирования файлов .odt (шаблон) и сохраняю их как odt.Все работает нормально, но когда я пытаюсь преобразовать ODT в PDF, я получаю эту ошибку:

ODFConverterException: java.lang.ClassCastException: вставка недопустимого элемента: 12

Эта ошибка вызвана текстовым полем в моем исходном файле odt.

От odt до odt все работает нормально, это сохраняет мое текстовое поле.

Поэтому я попытался изменить свои зависимости в pom нановейшая версияТеперь у меня больше нет этой проблемы, но она генерирует PDF-файл без текстового поля.

Мне действительно нужен PDF-файл с текстовым полем, в интернете я обнаружил, что ODFConvertor ограничен.

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);
}

мой 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>

Может кто-нибудь дать решение сохранить мое текстовое поле в pdf или другое решение для преобразования моего odt в pdf с моими текстовыми полями?

...