font size, tomcat pdf generation

0

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:

JasperPrint jasperPrint = JasperFillManager.fillReport(dot_jasper_file,  hashMap, conn);
byte[] pdfBytes = JasperExportManager.exportReportToPdf(jasperPrint);
 

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.

 

Attachments: 
am06's picture
21
Joined: Feb 7 2014 - 12:33pm
Last seen: 1 year 1 month ago

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?

diyosifova - 5 years 3 months ago

2 Answers:

1

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

am06's picture
21
Joined: Feb 7 2014 - 12:33pm
Last seen: 1 year 1 month ago

Thank you very much! It works just fine now.

diyosifova - 5 years 3 months ago

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 ??

juanzorrillaaa19 - 4 years 8 months ago

you only need to compile the jrxml once. Then you can use the created .jasper as if you created it with jasperstudio and you'll not loose computational time at each report generation.

am06 - 4 years 8 months ago
show 1 more...

I just saw this; it's a problem of versions. The most accurate solution is to download the correct version of ireport, if your project is using jasperreports-4.0.6.jar, the you need to download that version if ireport and compile with it.

jony404 - 4 years 6 months ago
0

You probally using an older version of jasperreport library in your application. 

Try to use jasperreports-X.X.X.jar compatible with the version that you use to create teh jasper file.

msmeirelles's picture
Joined: Dec 27 2009 - 8:25am
Last seen: 4 years 4 months ago
Feedback