skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Monday, October 22, 2012

Jasper report as pdf

Posted by Raju Gupta at 8:00 PM – 0 comments
 
prints the report in pdf format.

//import it in the java file

import net.sf.jasperreports.engine.JasperExportManager;
// a function ehich calls the jasper to generate the report
private String generatePldbbyCC(ParameterReportCriteria prcObject, Map reportMap) throws Exception {
 JasperPrint jasperPrint = null;
 JRFileVirtualizer virtualizer = null;
 String destFileLoc = null;
 File sourceFile = null;
 File destFile = null;
 ESpecDAOController control = new ESpecDAOController();
 // puts the parameters to jasper.
 parameters.put(Constants.COMPETITIVE_CATEGORIES, prcObject.getSelectedCompCategs()); 
 parameters.put("REPORT_CONNECTION", control.getMasterConnection());
 parameters.put(EspecConstants.CURR_TIME, "Exported: " + new SimpleDateFormat("M/d/yyyy 'at' hh:mm:ss a").format(DateUtil.getCurrentDateTime()));

 PropertiesVO templatePath = setJasperpath();

 virtualizer = new JRFileVirtualizer(1, templatePath.getValue());

 parameters.put(SUBREPORT_DIR, templatePath.getValue());

 parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);

 try {

  jasperPrint = JasperFillManager.fillReport(templatePath.getValue() + "/sample.jasper", parameters, control.getMasterConnection());

 } else {
  //get the file with extension as pdf
  destFile = new File(templatePath.getValue(), jasperPrint.getName() + "_" + prcObject.getProcessId() + ".pdf");

 } 

 destFileLoc = destFile.toString();
 //exports the report as pdf.
 JasperExportManager.exportReportToPdfFile(jasperPrint,destFileLoc);


Labels: PDF Generation Example

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger