Reputation: 10320
I have a report that is exported to XLSX and PDF. The code of both exporters is pretty similar at the same time encoding is lost during PDF export.
For instance, the following symbols are simply skipped in the end result: "Č", "ć". At the same time "ü", "ß" are printed correctly.
In XLSx exporter (working part) I use pretty simple code:
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
JRXlsxExporter xlsExporter = new JRXlsxExporter();
xlsExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
xlsExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream));
xlsExporter.exportReport();
return outputStream.toByteArray();
}
In case of PDF I use pretty the same code (doesn't work):
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream));
exporter.exportReport();
return outputStream.toByteArray();
}
But it doesn't work. In both cases I pass the same instance of jasperPrint
.
I tried playing around with PdfExporterConfiguration
to set up some parameters, but unfortunately haven't found any encoding related configuration.
Q: What might cause the problem? Any idea how to fix it?
Upvotes: 0
Views: 1378
Reputation: 3131
My suspision is that the problem comes from the fonts you are using. Are you sure both XLSX and PDF support the font you have set in your report? In the generated PDF you can check the used font by right-clicking and choosing document properties - there is a tab with fonts. Does the font in PDF support those symbols?
If I remember correctly sometimes when exporting to PDF the exporter will use some different font (if the one you wanted is not found/supported or something).
Upvotes: 1