4 Replies Latest reply on Sep 4, 2008 1:01 PM by Ben Catherall

    iText - save to file

    Chua Khoon Yong Novice

      hi,


      I hope some1 can help with this query :)


      Let say i got a web page (xhtml) with generate pdf using iText.  It would display nicely on the website.  But sometimes i may want to use the same xhtml to generate pdf document and send by email or let user download by clicking on a button.


      How to go about generating the pdf file using the xhtml?


      Many thanks.

        • 1. Re: iText - save to file
          Nicklas Karlsson Master

          I recall that the document tag places its content in a ValueHolder if it is nested in one.


          One option would be to file for a feature request in the lines of add an exportKey attribute to document that would hang the DocumentData on the key instead of redirecting if exportKey is non-null and see what NR has to say. I'm thinking of doing something like that for excel, you could then use a Render and fetch the result...

          • 2. Re: iText - save to file
            Chua Khoon Yong Novice

            hi Nicklas,


            Saw ur postings at http://seamframework.org/Community/ExportToPdfOrExcelFromRichdataTable.  Nice work for excel, hope there is something for the pdf?



            <p:document xmlns:ui="http://java.sun.com/jsf/facelets"
                        xmlns:s="http://jboss.com/products/seam/taglib"
                        xmlns:p="http://jboss.com/products/seam/pdf"> 
                
                <p:paragraph>Complicated pdf charts report</p:paragraph>
            </p:document>
            



            About the ValueHolder u mentioned, where is it and how to use it?


            Thank you.

            • 3. Re: iText - save to file
              Nicklas Karlsson Master

              When I find time, I'll see if I could extract the datatable and pass it through a PDF renderer also. If there is interest, file a JIRA so I don't forget about it...


              A ValueHolder is an interface that is implemented by most controls (HtmlInputHidden, HtmlInputSecret, HtmlInputText, HtmlInputTextarea, HtmlOutputFormat, HtmlOutputLabel, HtmlOutputLink, HtmlOutputText, HtmlSelectBooleanCheckbox, HtmlSelectManyCheckbox, HtmlSelectManyListbox, HtmlSelectManyMenu, HtmlSelectOneListbox, HtmlSelectOneMenu, HtmlSelectOneRadio, UIInput, UIOutput, UISelectBoolean, UISelectMany, UISelectOne).


              Reading the code of the Document.encodeEnd, I get the picture that if the document has the attribute sendRedirect=false and you have something in the lines of


              <h:inputText ...>
                <p:document sendRedirect="false">  
                </p:document>
              </h:inputText>
              



              The DocumentData object should end up in the value of the inputText.


              I haven't tried it myself and I must say I can't get my mind around to how it can work but it's worth a try, I don't think Norman put the code there without a reason...

              • 4. Re: iText - save to file
                Ben Catherall Newbie

                That's a nice idea - ValueBinding to store DocumentData.


                In the mean time you can achieve via this old post