title: Show Pdf file in Primefaces page
body: <p>I am generating a pdf file with Itextpdf package in jsf managed bean , now I want when user click on p:commandButton , user can see the pdf file in page2.xhtml from p:media .</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org    /TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://xmlns.jcp.org/jsf/html"
        xmlns:p="http://primefaces.org/ui"&gt;
      &lt;h:head&gt;
          &lt;title&gt;Facelet Title&lt;/title&gt;
      &lt;/h:head&gt;
      &lt;h:body&gt;
          &lt;h:form&gt;
              &lt;p:inputText value="#{bean.text}" /&gt;
              &lt;p:commandButton value="Show Pdf File" action="page2" /&gt;
          &lt;/h:form&gt;
  
      &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and Page2.xhtml is :</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:p="http://primefaces.org/ui"&gt;
      &lt;h:head&gt;
          &lt;title&gt;Page 2&lt;/title&gt;
      &lt;/h:head&gt;
      &lt;h:body&gt;
          &lt;p:media value="??????????" width="500px" height="500px" player="pdf" /&gt;
      &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and my bean file is :</p>
  
  <pre><code>    package pack;
  
  import com.itextpdf.text.Document;
  import com.itextpdf.text.Paragraph;
  import com.itextpdf.text.pdf.PdfWriter;
  import java.io.ByteArrayInputStream;
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.InputStream;
  import java.io.OutputStream;
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.RequestScoped;
  
  
  @ManagedBean
  @RequestScoped
  public class bean {
  
      private String text;
  
      public String getText() {
          return text;
      }
  
      public void setText(String text) {
          this.text = text;
      }
  
  
  
      /**
       * Creates a new instance of bean
       */
      public bean() {
          this.create_pdf();
      }
  
      public void create_pdf(){
          try {
              Document doc = new Document();
              OutputStream file = new FileOutputStream(new File("HelloWorld.pdf"));
  
              PdfWriter writer = PdfWriter.getInstance(doc, file);
  
              doc.open();
              doc.add(new Paragraph("A Hello World PDF document."));
              doc.add(new Paragraph(this.text));
              doc.close(); 
              file.close();            
          } catch (Exception e) {        }
  
      }
  
  }
  </code></pre>