2001 JI Open Discussion Posted August 17, 2006 Share Posted August 17, 2006 By: Mark Smith - marksmithurbana exportReportToPdfStream - how to set filename 2002-11-12 09:51Hi, Is there a way to set the filename of the PDF that gets sent down the stream from within my servlet when using JasperExportManager.exportReportToPdfStream()? Currently it sets the filename to be a section of my URL. Is there somehting in the HTML specification or MIME type rules that allows one to define the filename the user sees when downloading? Thanks, Mark By: Paulo Soares - psoares33 RE: exportReportToPdfStream - how to set filename 2002-11-12 10:05There are headers for it but it will work or not depending on the browser and version. It's very unreliable. By: Sofiane - sofianito RE: exportReportToPdfStream - how to set file 2002-11-13 06:45You should set the response header the following way. This works for netscape and mozilla, for IE it appears that the field CONTENT-DISPOSITION is obsolete and kept for backward compatibility, maybe there is a patch for IE... So if u don't want the pdf to be opened in the browser here is what u should do: String filename = "whatever"; response.setContentType( "application/octet-stream" ); response.setHeader( "Content-Disposition", "attachment; filename="" + filename + ".pdf";" ); if u want the pdf to be opened directly into the browser just change the mime type: response.setContentType( "application/pdf" ); response.setHeader( "Content-Disposition", "attachment; filename="" + filename + ".pdf";" ); If it doesn't work in IE , try to set the content length : byte[] bytes = JasperRunManager.runReportToPdf( "myreport.jasper", map, conn ); response.setContentLength( bytes.length ); ServletOutputStream out = response.getOutputStream(); out.write( bytes, 0, bytes.length ); Good Luck Sofiane 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