Hi,
I have a problem with my JRXML file created in Jaspersoft Studio. When I'm previewing the file in Studio, or when I'm using the Java class JasperViewer - everything looks PERFECT, exactly as in the Report Design view.
But when I am trying to export it to the PDF file like this:
InputStream invoiceJasper = MainJasper.class.getResourceAsStream("/invoices/invoice.jrxml"); InputStream taskTableJasper = MainJasper.class.getResourceAsStream("/invoices/invoice_sub.jrxml"); JasperDesign mainReportDesign = JRXmlLoader.load(invoiceJasper); JasperDesign tableReportDesign = JRXmlLoader.load(taskTableJasper); JasperReport report = JasperCompileManager.compileReport(mainReportDesign); JasperReport table = JasperCompileManager.compileReport(tableReportDesign); mainReport = JasperFillManager.fillReport(report, map, new JREmptyDataSource()); tableReport = JasperFillManager.fillReport(table, map, new JREmptyDataSource()); List<JasperPrint> printList = new ArrayList<>(); printList.add(mainReport); printList.add(tableReport); JRPdfExporter exporter = new JRPdfExporter(); exporter.setExporterInput(SimpleExporterInput.getInstance(printList)); //Set as export input my list with JasperPrint s exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("/home/znitecki/output.pdf")); //or any other out streaam SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration(); configuration.setCreatingBatchModeBookmarks(true); //add this so your bookmarks work, you may set other parameters exporter.setConfiguration(configuration); exporter.exportReport();
Everything is falling apart. The main design remains intact, but the font setting is lost (In the designer I am using Times New Roman font), and almost all the polish characters used in text (ąłęćźż) are missing. They just dissapear, when I have a word: BĘDĄCYCH, all that remains in the PDF file is BDCYCH. It also looses any styling (i have a few places where I am using markup = html, and the bold text is no longer bold...)
THE SAME THING happens when I am trying to export the PDF file FROM Jaspersoft Studio. A regular preview is 100% correct with correct fonts and polish characters, but the export function looses all the fonts and html styling too.
I am working on UBUNTU 18.04, I have the ubuntu-restricted-extras package installed...
Am I missing something in my operating system? or in the Jaspersoft Studio configuration? Or the JRXML file configuration? Or something in the JAVA code?
2 Answers:
I have solved the problem with exporting from the Jaspersoft Studio by adding the font path in Window->Preferences->Fonts. The problem with Java-side was simple to solve, I have found out that I have to select used fonts from Window-Preferences-Fonts and export them as a Jar (as fonts.jar), and add them to my classpath.
I am using Gradle so i have created a libs directory in the root folder of the project, and the configuration looks like this:
build.gradle:
dependencies { ... compile files('libs/fonts.jar') ... }
Are you using font extensions? Most font problems with pdf is with font extensions.
https://community.jaspersoft.com/wiki/custom-font-font-extension
Hi, How to add the jasper report dependency in springboot gradle project? Thanks