How to open a new pdf file in a new browser tab with iText Java
<p>I'm pretty sure it's gonna be an easy solution but i can't find any help about my issue. I'm creating a pdf file and at the moment users have to save it before opening it. But i have to open it before the user decides to save it or not. But i can't find how to tell iText to open it in a new tab. What sould i do?</p>

<p>Here is my code, i call this method right after  "document.close();" :  </p>

<pre><code>public void openPDF(String nomDoc, String nomFichier) throws IOException {

    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    HttpServletResponse response = (HttpServletResponse) externalContext
            .getResponse();

    // File file = new File(getFilePath(), getFileName());
    File file = new File(nomFichier);
    BufferedInputStream input = null;
    BufferedOutputStream output = null;

    try {

        input = new BufferedInputStream(new FileInputStream(file),
                DEFAULT_BUFFER_SIZE);

        response.reset();
        response.setHeader("Content-Type", "application/pdf");
        response.setHeader("Cache-Control",
                "must-revalidate, post-check=0, pre-check=0");
        response.setHeader("Content-Length", String.valueOf(file.length()));
        // response.setHeader("Content-Disposition", "inline; filename=\"" +
        // nomFichier + "\"");
        response.setHeader("Content-Disposition", "form-data;filename=\""
                + nomDoc + "\"");
        output = new BufferedOutputStream(response.getOutputStream(),
                DEFAULT_BUFFER_SIZE);

        byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
        int length;
        while ((length = input.read(buffer)) &gt; 0) {
            output.write(buffer, 0, length);
        }
        output.flush();

    } finally {
        close(output);
        close(input);
    }
    facesContext.responseComplete();
}
</code></pre>

<p>My command button :</p>

<pre><code>&lt;p:commandButton process="checkboxContrats"
                        icon="ui-icon-file-pdf" value="Editer les fiches de paie"
                        action="#{paieAgentView.printPaieAgent()}" update="@form"
                        escape="false" ajax="false" /&gt;
</code></pre>

<p>My view : </p>

<pre><code>public void creerPDF(List&lt;FichePaie&gt; listFdP, Date dateDebut, Date dateFin) throws DocumentException,
        IOException {
    ServletContext servletContext = (ServletContext) FacesContext
            .getCurrentInstance().getExternalContext().getContext();
    String nomRelatif = servletContext.getRealPath(NOMFICHIER);

    Date dtt = new Date();
    Phrase para = new Phrase("Date d'édition : " + sdf.format(dtt),
            FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL));
    Document document = this.getDocumentPortraitSmallMargin(nomRelatif,
            para);

    document.open();
    document.add(new Chunk(""));

    document.close();
    openPDF(filename, nomRelatif );

}
</code></pre>

<p>Thank you for your help.</p>