Jump to content

i want to generate pdf file direcly in jasper repo


anupp

Recommended Posts

Code:
Hi All,
i want to generate pdf file directly.when click the save button then directly pdf file should be generated.Actually i have generated pdf file through jasper but i have mentioned destination so its not required.My Requirement is after clicking the save button then pdf should be generated.

HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
String reportPath =
request.getSession().getServletContext().getResource("/reports").toString().substring(6); // substring cuts off the 'file://'
File file = new File(reportPath + "TransferSecretaries_Report.jasper");
String file1 = file.toString();
String dest = "c:/transferSecreatary.pdf";

jasperPrint =JasperFillManager.fillReport(file1, new HashMap(),simpleDS);
//generates PDF
JasperExportManager.exportReportToPdfFile(jasperPrint, dest);

}
Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Make sure you have the Headers set correctly. For example, in PHP you would do:

header('Cache-Control: private');
header('Content-Description: File Transfer');
header("Content-Disposition: attachment, filename=$filename.pdf");
header('Content-Type: application/pdf');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . strlen( $result ) );

In Java, you have to use the HttpServletResponse, I believe, and I don't know if it automatically sets the content-length for you.

Also, the Cache-Control makes sure that IE does not cache the results of the PDF each time -- otherwise you can't get a new PDF!



Post Edited by thangalin at 05/31/2010 07:00
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...