title: Liferay - Creating PDF and outputing to stream
body: <p>Having a little trouble here. Basic premise is that I need to hit a button, generate HTML, create PDF, and throw into output-stream for download:</p>
  
  <pre><code>&lt;ice:commandButton title="Download"
      image="/images/dl.png"
      value="Download"
      action="#{bean.downloadPDF}"&gt;        
  &lt;/ice:commandButton&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>public void downloadPDF() throws IOException {
  
      PD4ML pdf = new PD4ML();
      pdf.setPageSize(PD4Constants.LETTER);
      pdf.setPageInsets(new Insets(0, 0, 0, 0));
      pdf.setHtmlWidth(1000);
      pdf.enableImgSplit(false);
      pdf.generateOutlines(false);
  
      File pdfFile = new File("tmp.pdf");
      FileOutputStream fos = new FileOutputStream(pdfFile);
  
      StringReader sr = new StringReader("&lt;p&gt;Testing Download&lt;/p&gt;");
      pdf.render(sr, fos);
  
      FacesContext facesContext = FacesContext.getCurrentInstance();
      PortletResponse portletResponse= (PortletResponse)facesContext.getExternalContext().getResponse();
      ResourceResponse portletResourceResponse = (ResourceResponse) portletResponse;
      portletResourceResponse.setContentType("application/pdf");
  
      OutputStream out = portletResourceResponse.getPortletOutputStream();
      out.flush();
      facesContext.responseComplete();
  }
  </code></pre>
  
  <p>Problem I am having is after the <code>pdf.render()</code>, when I attempt to generate the response based on the current context and the convertion to <code>ResourceResponse</code>:</p>
  
  <pre><code>java.lang.ClassCastException: com.liferay.portlet.RenderResponseImpl cannot be cast to javax.portlet.ResourceResponse
  </code></pre>
  
  <p>What is the proper way to take that file and output it in Liferay/portlet?</p>