Hello,
I created a report under Jaspersoft Studio (under OSX). Everything is fine with it, I can change the font size or use custom fonts (preferences->fonts). Rendering the report with "preview" and "export as pdf" are both fine.
I render the pdf with the standalone application jasperserver-ws-sample.war under tomcat 7, Ubuntu, and a custom executeReport.jsp:
Everything is fine (parameters, data filled from sql, layout, pdf) except two things:
- whatever the font size in the jasper file, the pdf use font.size=10
- default font (SansSerif) render as Helvetiva (I'm fine with this), but custom fonts prevent the pdf generation (seems it doesn't use the jar file containing fonts, created with Jaspersoft Studio and saved in webapp/WEB-INF/lib).
I would be happy to change font size (below 10).
Thank you
PS: I use the war file without jasperserver installed.
2 Answers:
yes I solved it.
- do NOT use the .jasper file created with jaspersoft studio
- compile the .jrxml into a .jasper file with a java program
Here is the list of the files needed by the java program (in ./lib):
commons-beanutils-1.8.0.jar commons-collections-3.2.jar commons-digester-1.7.jar commons-logging.jar itext-2.1.7.js2.jar jasperreports-5.5.0.jar mysql-connector-java-5.1.28-bin.jar servlet-api-2.4.jar
The java program is:
import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.sql.Connection; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRExporter; import net.sf.jasperreports.engine.JRExporterParameter; import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.export.JRPdfExporter; import java.sql.*; /** * You'll need these jar's below: * * jasperreports-5.0.1.jar * iText-2.1.7.jar (needed to generate PDF) * jfreechart-1.0.12.jar (needed to graphics and charts) * jcommon-1.0.15.jar (needed to graphics and charts) * commons-beanutils-1.8.2.jar * commons-collections-3.2.1.jar * commons-digester-2.1.jar * commons-logging-1.1.jar */ public class compil_jrxml { public static void main(String[] args) { int count = args.length; try { if (count>0) { String reportName = args[0]; String str[]=reportName.split("\\."); String reportName_jasper = str[0] + ".jasper"; // compiles jrxml JasperCompileManager.compileReportToFile(reportName, reportName_jasper); } } catch (Exception e) { throw new RuntimeException("It's not possible to generate the jasper report.", e); } } }
to compile the java program:
javac -classpath ./lib/jasperreports-5.5.0.jar compil_jrxml.java
and finally to compile a .jrxml and h-generate the .jasper:
java -cp .:./lib/jasperreports-5.5.0.jar:./lib/commons-logging.jar:./lib/commons-digester-1.7.jar:./lib/commons-collections-3.2.jar:./lib/servlet-api-2.4.jar:./lib/commons-beanutils-1.8.0.jar:./lib/itext-2.1.7.js2.jar:./lib/mysql-connector-java-5.1.28-bin.jar compil_jrxml report.jrxml
Thank you very much! It works just fine now.
I've done the same way, compiling the .jrxml from java and it works. But doing it this way is slower and computational time is lost, so I want to do it from the .jasper but does not work this way. Any solution for this ??
Hi,
I'm having a similar issue. I needed Times New Roman font, so I add it as suggested in the comments of this post. And it works fine, but no matter what font size is set in the report, in the export file (pdf or docx), the font size is always the default one - 10.
Did you find a solution for your font size problem?