#java #pdf #itext #pdf-generation #xdocreport
#java #PDF #itext #генерация PDF #xdocreport
Вопрос:
Я использую 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 с моими текстовыми полями?