0

Hi all and thanks for taking the time to answer my question.

I'm trying to send an array of bytes to the client so that his browser can reconstruct in e PDF file. Below is my code:

        OutputStream out = response.getPortletOutputStream();

        response.setProperty("Content-Disposition", "attachment; filename=" + fileName + ".pdf");
        response.setContentType("application/pdf");

        out.write(pdfInvoice);
        out.flush();
        out.close();

We're working with Liferay Portlets but that should not make a difference. pdfInvoice is the byte array. Nothing happens when this code executes. Can you spot what's wrong? Thanks in advance!

Dragan
  • 3,713
  • 12
  • 42
  • 59
  • Are you sure that the code is executed? Can you show whole handler method with annotations and your resourceURL tag? What happens when you click on the link (is any response returned? use HTTPFor or similar tool) – František Hartman Jul 16 '12 at 08:51

1 Answers1

0

You can't serve a pdf in a Portlet response like that, the standard approach is to create a servlet which serves the PDF to the client.

If you want to serve the PDF inside a Portlet this guide should help http://www.liferay.com/community/wiki/-/wiki/Main/Generate+PDF+File+in+Portlet

Mark Bakker
  • 1,278
  • 8
  • 19
  • hey Mark. I am doing this inside a ResourceMapping method. I have previously done the same for Excel. Returned it from a Resource Mapping method and worked perfectly – Dragan Jul 13 '12 at 14:22
  • 2
    http://stackoverflow.com/questions/8654568/serve-pdf-in-spring-portlet-mvc-architecture-liferay-6-0-6 – Mark Bakker Jul 13 '12 at 14:35
  • Using servlet is outdated. Resource phase is the correct approach. – František Hartman Jul 16 '12 at 08:47
  • I agree for more complex usecases, but for serving something as simple as a PDF which will not do anything with the portlet state. Using resource phase will make the solution unnecessary complex. (personal opinion) – Mark Bakker Jul 16 '12 at 08:54