Skip to Content
0
Sep 20, 2008 at 02:46 PM

How to rename the outputted PDF file in the Response object?

207 Views

Hi,

Every report that I export in my servlet app will have the filename of the java class file plus the pdf extension, for example, the page "printreport" will generate "printreport.pdf", how can I rename the outputted file?

This is my code, which does not change the filename right now:

ReportClientDocument reportClientDoc = new ReportClientDocument();
reportClientDoc.open(reportname, OpenReportOptions._openAsReadOnly);
Object reportSource = reportClientDoc.getReportSource();
...
...
response.reset();
response.setContentType("application/pdf");
response.addHeader("content-disposition", "inline; filename=MyCustomReportName.pdf");
response.addHeader("Content-Disposition", "attachment;.filename=MyCustomReportName.pdf");
response.flushBuffer();      
exportControl.processHttpRequest(request, response, getServletConfig().getServletContext(), null);

Thank you!