I use xdocreport with the follow dependencies:
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>xdocreport</artifactId>
<version>2.0.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/fr.opensagres.xdocreport/fr.opensagres.xdocreport.converter.docx.xwpf -->
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.poi.xwpf.converter.pdf</artifactId>
<version>2.0.4</version>
</dependency>
Code:
ITemplateEngine templateEngine = VelocityTemplateEngine.getDefault();
InputStream in= new FileInputStream(new File("ODTHelloWordWithVelocity.odt"));
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in,templateEngine);
// 2) Create Java model context
IContext context = report.createContext();
context.put("name", "world");
// 3) Set PDF as format converter
Options options = Options.getTo(ConverterTypeTo.PDF);
// 3) Generate report by merging Java model with the ODT and convert it to PDF
OutputStream out = new FileOutputStream(new File("ODTHelloWordWithVelocity_Out.odt"));
report.convert(context, options, out);
and, as result:
com.lowagie.text.ExceptionConverter: Cannot read the array length because "this.NewSubrsIndexNonCID" is null
How to fix it, What NewSubrsIndexNonCID is ?
I expect to get pdf document. If I use Doc4j, it works as expected. But DOC4J is very slowly. To convert 4 pages to pdf it takes about 5 seconds and above.
UPD. Stack trace: 2023-08-29T18:11:38.381+03:00 ERROR 13480 --- [nio-8080-exec-3] f.o.x.c.d.p.i.XWPF2PDFViaITextConverter : java.lang.NullPointerException: Cannot read the array length because "this.NewSubrsIndexNonCID" is null 2023-08-29T18:11:38.385+03:00 ERROR 13480 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.RuntimeException: fr.opensagres.xdocreport.converter.XDocConverterException: fr.opensagres.poi.xwpf.converter.core.XWPFConverterException: java.lang.NullPointerException: Cannot read the array length because "this.NewSubrsIndexNonCID" is null] with root cause
com.lowagie.text.ExceptionConverter: Cannot read the array length because "this.NewSubrsIndexNonCID" is null
looks like problem with fonts. If I use Calibri, it works fine.
Ok, I try add new fonts:
@PostConstruct
public void init() {
var fonts = resourceLoader.getResources("classpath:fonts/*");
for (var font : fonts) {
FontFactory.register(font.getURL().toString());
}
}
But result the same....
I have nearly the same code running with