anupp Posted May 31, 2010 Share Posted May 31, 2010 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 More sharing options...
thangalin Posted May 31, 2010 Share Posted May 31, 2010 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now