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()+"?pdf=true";          
        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);
            outputstream.close();

        } catch (Exception e) {
        }
        facesContext.responseComplete();

    }

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>

but values of are not being shown in pdf. Only the values of are shown.

rashidali
  • 330
  • 1
  • 5
  • 16
  • 1
    Are you indeed implying that when you manually open the exact URL as represented by `"http://localhost:8080/digitalisation_lstp/chef/rapport.xhtml;jsessionid="+session.getId()+"?pdf=true"` in your webbrowser, then you *do* see the desired content? Because your problem suggests that this is actually also not the case, and thus it's not an iText problem at all. Namely, it's just a presenter of the result. If the result is wrong in first place, then the presenter can't help much on that. – BalusC May 17 '19 at 11:41
  • @BalusC please view the updated description. – rashidali May 17 '19 at 13:22
  • I guess that you didn't understand me .. OK, let's take baby steps now. In your code, remove the entire `try` block from the code. Then add a `System.out.println(url);` to the code. Then run the code. Then look in server log. Then copy the printed URL. Then paste it in your browser's address bar. Then press [enter]. Now look at that page. This is exactly the same page as how iText would see it. You should now start to understand that this problem is not caused by iText. You only have to fix code behind your page in such way that the copypasted URL gives exactly the expected result. – BalusC May 17 '19 at 14:08
  • @BalusC you are right, the url also does not display anything. – rashidali May 17 '19 at 15:19
  • @BalusC I replaced the tag with some static values, the values are still not being shown. – rashidali May 17 '19 at 15:20
  • the attribute of value in output tags doesn t work. Idk why? – rashidali May 17 '19 at 15:24
  • So the `FacesServlet` is actually not invoked? What's the normal URL of this page? You used `/chef/rapport.xhtml` so the `FacesServlet` must be mapped to an URL pattern of `*.xhtml` else it won't run. – BalusC May 17 '19 at 16:06
  • @BalusC servlet-name : Faces Servlet and url-pattern : /faces/* – rashidali May 17 '19 at 17:35
  • So the `/chef/rapport.xhtml` is thus indeed not the normal URL of this page? Why don't you use the normal URL of this page? Forget iText for now. What exactly is the normal URL of this page? Once you figure out that, then you can just pass it to iText. – BalusC May 19 '19 at 11:09

0 Answers0