By: Mark Smith - marksmithurbana
exportReportToPdfStream - how to set filename
2002-11-12 09:51
Hi,
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:05
There 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:45
You 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
exportReportToPdfStream - how to set filename
2002-11-12 09:51
Hi,
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:05
There 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:45
You 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
0 Answers:
No answers yet