2 Replies Latest reply on Aug 31, 2015 9:58 PM by cathy ben

    pdf generation with images (from html source)

    Raphaël M. Newbie

      Hello,


      I have a problem in a pre-production environment with my application.
      I am generating on the fly pdf from contents stored in the database in html.




      <p:html>
         <font size="3" face="Arial" style="text-align:justify">
            <h:outputText escape="false" value="#{document.content}" style="text-align:justify"/>
         </font>
      </p:html>





      The thing is that there are images in these contents. Oh Just the url of the images, images are stored on the server.


      So when i was working in dev on localhost the pdf were corretly generated with images.


      <img scr="http://localhost:8080/media/myimage.jpg />



      But now in pre-production images are not insert in the document. And there are no errors in the logs.


      <img scr="http://media.mysubdomain.com/myimage.jpg />



      I try to replace the url by a full path on the server, and by htpp://localhost/media with a proxy on apache but there are still no displaying of any images...



      Is there something to do to make it work that i miss?


      Bye
      Raphaël




        • 1. Re: pdf generation with images (from html source)
          Raphaël M. Newbie

          Ok i have change the way i generate my pdf.


          I split my text between html and images.
          I load images from a absolute path in a BufferedImage


          And generate my pdf like this :



          <ui:repeat value="#{documentPdf.pagesPdf}" var="_page" >
               <ui:repeat value="#{_page.elements}" var="_element">
                    <p:html>
                         <font size="3" face="Arial">
                              <h:outputText escape="false" value="#{_element.htmlContent}"/>
                         </font>
                    </p:html>
                    <s:fragment rendered="#{_element.image}">
                         <p:table columns="1" widthPercentage="100"  borderWidth="0">
                              <p:cell borderWidth="0">
                                   <p:image value="#{_element.imageContent}"/>
                              </p:cell>
                         </p:table>
                    </s:fragment>
               </ui:repeat>
               <p:newPage/>
          </ui:repeat>



          • 2. Re: pdf generation with images (from html source)
            cathy ben Newbie

            Thank you for the guide. I only find a guide about creating PDF from stream. Your code is of great help.