JRXML file looks fine in Jaspersoft Studio and JasperViewer, looks terrible as PDF


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

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?

zbigniew.nitecki's picture
Joined: Mar 21 2019 - 2:21am
Last seen: 3 years 9 months ago

Hi, How to add the jasper report dependency in springboot gradle project?  Thanks 

premm.dnn - 11 months 3 weeks ago

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:


dependencies {
   compile files('libs/fonts.jar')

zbigniew.nitecki's picture
Joined: Mar 21 2019 - 2:21am
Last seen: 3 years 9 months ago

Are you using font extensions? Most font problems with pdf is with font extensions.


hozawa's picture
Joined: Apr 24 2010 - 4:31pm
Last seen: 3 years 8 months ago