How do I change the font of the static text field while using jaspers to make the PDF?

0

No matter how many times I change or by how much I change the font size, it always stays the same in the generated pdf.  Due to this most of data in static fields is getting truncated. All the text on the pdf has the same font size. Any sugestions on how to change the font size. 

I'm using the following code to generate pdfs.

package rponte.report;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 rponte.report.ConnectionFactory;
public class ReportGenerator {                public static void main(String[] args) {
 
                                Connection connection = null;
                                try {
 
                                                String reportName = "myreport";
                                                Map<String, String> parameters = new HashMap<String, String>();
                                                parameters.put("ACCOUNT_NO","x");
                                                parameters.put("INVOICE_DATE","z");
                                                parameters.put("SEGMENT_ID","y");
                                                parameters.put("SUBREPORT_DIR","./");
                                                //step1 load the driver class  
                                                Class.forName("oracle.jdbc.driver.OracleDriver");  
 
                                                //step2 create  the connection object  
                                                connection=DriverManager.getConnection(  
                                                "jdbc:oracle:thin:@localhost:me","system","oracle");                                                    // compiles jrxml
                                                JasperCompileManager.compileReportToFile("Corporate.jrxml");
                                                // fills compiled report with parameters and a connection
                                                JasperPrint print = JasperFillManager.fillReport("Corporate.jasper", parameters, connection);
                                                // exports report to pdf
                                                JRExporter exporter = new JRPdfExporter();
                                                exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
                                                exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, new FileOutputStream(reportName + ".pdf")); // your output goes here
 
                                                exporter.exportReport();                                } catch (Exception e) {
                                                throw new RuntimeException("It's not possible to generate the pdf report.", e);
                                } finally {
                                                // it's your responsibility to close the connection, don't forget it!
                                                if (connection != null) {
                                                                try { connection.close(); } catch (Exception e) {}
                                                }
                                }
 
                }
 
}

kosalendra.singh1's picture
Joined: Dec 25 2018 - 8:17pm
Last seen: 1 month 1 week ago

1 Answer:

0

Font is specified in jrxml file. Be sure the specified font is available in your classpath.

hozawa's picture
39234
Joined: Apr 24 2010 - 4:31pm
Last seen: 1 day 4 hours ago
Feedback