Foren
How to serve a pdf as attachment
Nikos Samaras, geändert vor 7 Jahren.
How to serve a pdf as attachment
Junior Member Beiträge: 29 Beitrittsdatum: 14.01.16 Neueste Beiträge
Hello
I use Liferay EE and Spring mvc. I try to open a pdf as attachment when I click on download button but the pdf opens in the browses instead of serving an attachment pdf.
It seems that it does not care for
response.setHeader("Content-disposition", "attachment; filename=" + filename + ".pdf");
here is my source code.
Please can you help me?
Thank you
Nikos
I use Liferay EE and Spring mvc. I try to open a pdf as attachment when I click on download button but the pdf opens in the browses instead of serving an attachment pdf.
It seems that it does not care for
response.setHeader("Content-disposition", "attachment; filename=" + filename + ".pdf");
here is my source code.
@ActionMapping(params = "action=downloadZip")
private void downloadZip(ActionRequest actionRequest, ActionResponse actionResponse, Model model, @ModelAttribute("dossierView") DossierInfo dossierInfo) throws Exception {
LOG.info("Start downloading zip file");
final HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);
String fileName = "test";
String reportFormat = dossierViewService.downloadFiles(dossierInfo, response.getOutputStream());
response.setHeader("Content-disposition", "attachment; filename=" + filename + ".pdf");
response.setContentType(("application/pdf"));
response.flushBuffer();
response.getOutputStream().flush();
}
Please can you help me?
Thank you
Nikos
Juan Gonzalez, geändert vor 7 Jahren.
Move to more appropiate category
Liferay Legend Beiträge: 3089 Beitrittsdatum: 28.10.08 Neueste Beiträge
Move to more appropiate category
Arun Das, geändert vor 7 Jahren.
RE: How to serve a pdf as attachment
Regular Member Beiträge: 166 Beitrittsdatum: 23.07.12 Neueste Beiträge
Hi,
Try using serveResource instead of action method.
Arun
Try using serveResource instead of action method.
resourceResponse.setContentType("application/pdf");
resourceResponse.setProperty(HttpHeaders.CONTENT_DISPOSITION,"attachement;filename="+pdfName+".pdf");
try {
OutputStream os = resourceResponse.getPortletOutputStream();
//write your stuff here
os.close();
} catch (Exception ex) {
ex.printStackTrace();
}
Arun