5 Replies Latest reply on Jan 27, 2007 11:32 AM by norman.richards

    pdf form 'filling and generic overlay proposition

    kukeltje

      I've been looking a little into implementing generic text and image overlay for an existing PDF and output that as a new pdf.

      Besides needing a PdfStamper instead of a PdfWriter, there are some design issues to be made afaics.

      We could stil use the p:document as a base tag and add a overlay tag in that this overlay tag could take a file/url/... as an attribute and within that overlay tag we could allow a basic set of tags like page to select on which page to do overlay and within that tag we could allow text and image with postition, size, font etc to do basic things. An example for overlay would be:

      <p:document>
       <p:overlay src="/pdf/myExistingPdf.pdf">
       <p:page number="1">
       <p:text top="100" left="100" fontsize="10" fonttype="....">Hi, I'm overlayed text\n #{user.name} did this</p:text>
       </p:page>
       <p:page number="3">
       <p:image src="/jboss.jpg" top="225" left="150" />
       </p:page>
       </p:overlay>
      </p:document>
      


      or for filling out forms:

      <p:document>
       <p:form name="formId" flatten="true">
       <p:formElement name="name">#{formBean.name}</p:formElement>
       <p:formElement name="address" value="Address" />
       <p:formElement name="city" value="#{formBean.city}" />
       <p:formElement name="country">The Netherlands</p:formElement>
       </p:form>
      </p:document>


      Although the name attribute on the form element seems not to be needed (no examples with more than one form in a pdf and no api call to retrieve a specific form so there probably never is one)

      The 'flatten' attribute makes the document loose all it's input fields and just render as text (where should its' default be?)

      Any other suggestions?

        • 1. Re: pdf form 'filling and generic overlay proposition
          kukeltje

          hmmm... the form should also have a src attribute, but it might be easier (implementation wise) to add the src attribute to the document element and only allow form or overlay as it's children when this attribute is present (no idea what the behaviour will be if there also is a p:paragraph anywhere in this)

          • 2. Re: pdf form 'filling and generic overlay proposition
            kukeltje

            another option for the overlay is to have the overlay element take the page, top and left attributes and allow the two already existing outputText and image tage inside it.

            <p:overlay page="1" top="100" left="100">
             <p:outputtText >Hi, I'm overlayed text\n#{user.name} did this</p:text>
            </p:overlay>
            <p:overlay page="3" top="225" left="150">
             <p:image resource="/jboss.jpg" />
            

            I think I'll prefer that appoach and see if I get it working. (I need something on monday :-))

            • 3. Re: pdf form 'filling and generic overlay proposition

              Send any code you create. I don't think I'll be able to get to it until after 1.1.5 is released.

              • 4. Re: pdf form 'filling and generic overlay proposition
                kukeltje

                I will. No problem getting to it after 1.1.5. We can include anything we develop temporarily in our own version.

                I've been digging into the overlay stuff and the way the current implementation is done (clean and compliments btw, I got it real quick) is not usable for overlay. The PdfStamper that needs to be used dos not work with paragraphs, pages etc at all. It is at a much lover level. Completely new tags have to be defined.

                I will initially focus on just adding simple text and images to specified pages at a specific position with a certain fontfamily and fontsize (this allready works btw) but should be made a little better). Adding a watermark to each page or pagenumber or anything like that is skipped for now since it makes less sense imo.

                Filling out forms is the next thing and is also real simple. I'll send al the code I have over the weekend.

                • 5. Re: pdf form 'filling and generic overlay proposition

                  Great. Just attach patches to the appropriate JIRA issues.