0

I am trying to convert a JSF Page to PDF with Flying Saucer.

In the rapport.xhtml I have some backing bean parameters, which values should appear in the pdf. But they do not. If I access the xhtml page, then values showing correctly, I can see the pdf page with pure text that I have written but not the backing bean values.

this is my function in the backing bean for converting :

 public void createpdf() {

        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext excontext = facesContext.getExternalContext();
        HttpSession session = (HttpSession) excontext.getSession(true);

        String url = "http://localhost:8080/digitalisation_lstp/chef/rapport.xhtml;jsessionid=" + session.getId();

        try {
            ITextRenderer renderer = new ITextRenderer();
            //InputStream is = new URL(url).openStream();
            renderer.setDocument(new URL(url).toString());
            renderer.layout();
            HttpServletResponse response = (HttpServletResponse) excontext.getResponse();
            response.reset();
            response.setContentType("application/pdf");
            response.setHeader("content-Disposition", "inline: filename\"print-file.dpf\"");
            OutputStream outputstream = response.getOutputStream();
            renderer.createPDF(outputstream);
        } catch (Exception e) {
        }       

    }

And this is rapport.xhtml:

(the values I want to appear in the pdf)

<table style="" border="1">

                        <tr >
                            <td class="td1"> Dossier N </td>
                            <td class="td2">  <h:outputText value="#{rapportCtlr.afficher_rapport().num_dossier}"></h:outputText></td>
                        </tr>
                        <tr>
                            <td class="td1"> Client</td>
                            <td class="td2">   <h:outputText value="#{rapportCtlr.afficher_rapport().client}"></h:outputText></td>
                        </tr>
                        <tr>
                            <td class="td1"> Chantier</td>
                            <td class="td2">   <h:outputText value="#{rapportCtlr.afficher_rapport().chantier}"></h:outputText></td>
                        </tr>
                        <tr>
                            <td class="td1"> Prestation</td>
                            <td class="td2">   <h:outputText value="#{rapportCtlr.afficher_rapport().prestation}"></h:outputText></td>
                        </tr>
                        <tr>
                            <td class="td1"> Type de béton</td>
                            <td class="td2">  <h:outputText value="#{rapportCtlr.afficher_rapport().type_beton}"></h:outputText></td>
                        </tr>
                        <tr>
                            <td class="td1"> Lieu de pélèvement</td>
                            <td class="td2">   <h:outputText value="#{rapportCtlr.afficher_rapport().lieu_preleve}"></h:outputText></td>
                        </tr>
                        <tr>
                            <td class="td1">Rèf de rapport</td>
                            <td class="td2">  <h:outputText value="#{rapportCtlr.afficher_rapport().ref_rapport}"></h:outputText></td>
                        </tr>
                        <tr>
                            <td class="td1"> Date d'émission</td>
                            <td class="td2">  <h:outputText value="#{rapportCtlr.afficher_rapport().date_emission}"></h:outputText></td>
                        </tr>
                        <tr>
                            <td class="td1"> Date de prèlèvement</td>
                            <td class="td2">   <h:outputText value="#{rapportCtlr.afficher_rapport().date_preleve}"></h:outputText></td>
                        </tr>
                    </table>
Kukeltje
  • 12,223
  • 4
  • 24
  • 47

1 Answers1

0

UPDATE: i have found that the problem is in the XHTML TAGS , the outputText tag is not converted or not being shown in the pdf page , maybe the itext can't convert it well

  • Hi, this is not an answer but an update of the question and precicely what BalusC meant in his comments. iText should not render the xhtml tags, the jsf feacelet renderer should do that and iText should convert the html to pdf – Kukeltje May 21 '19 at 06:21