3

I have a PDF document which I am filling with dynamic content from a html form. Up until now it has only been text and checkboxes. However I now need to add an image into the PDF (the image is always changing).

Using the code at http://koivi.com/fill-pdf-form-fields/ I am creating creating a XFDF file, then simply running it and the data appears in the correct places.

How would I get this working so that I can also load in a dynamic image? I have read a couple places about creating a button but that hasn't seemed to work.

xfdf source;

<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
    <fields>
        <field name="first_name">
            <value>John</value>
        </field>
        <field name="last_name">
            <value>Doe</value>
        </field>
        <field name="somekindofimageplaceholder">
            <value>data:image/png;base64,iVBORw0dfsfsdsdf...</value>
        </field>
    </fields>
<ids original="f87c5ab87f1666163abd9537ba917f11" modified="1404772492" />
<f href="mypdf.pdf" />
</xfdf>

Ideally I wanted to use a base64 string but this isn't a necessity. I looked over at the xfdf spec and there is a snapshot element which takes base64 strings for images but this is just for 3dviews..? http://partners.adobe.com/public/developer/en/xml/XFDF_Spec_3.0.pdf

Any help would be greatly appreciated. Cheers.

EDIT: I couldn't find a solution for doing this in pure XFDF. As a hacky work around I'm creating the PDF form with a XFDF file then merging it using PDFTK with another generated PDF which contains the image.

Patrick
  • 100
  • 1
  • 8
  • Normally, I use FDF for such a scenario, and there, I do not embed the image, but use a link to it. You might look at the FDF description (in the ISO 32000 document, or in the specs provided by Adobe in the Acrobat SDK), and let you guide by that. – Max Wyss Jul 08 '14 at 00:13
  • Thanks for the response. I'm at work so can't test this. Would the following code segment work? imageHolder is a button which is read and icon only. ` image.png ` \nSorry for the spoon feeding, I have no knowledge of working with PDF apart from reading books! – Patrick Jul 08 '14 at 07:28
  • I'd have to check that in the documentation. Note that Button fields do not have the name property. This may take a moment. – Max Wyss Jul 08 '14 at 09:32
  • I couldn't find a solution for this so I've made a hacky workaround. I'm creating the PDF form with a XFDF file then merging it using PDFTK with another generated PDF which contains the image. If you manage to find a better solution I'd love to hear it. – Patrick Jul 09 '14 at 07:11
  • As stated, FDF instead of XFDF would make it possible. Another approach would be server-side filling. – Max Wyss Jul 09 '14 at 07:33
  • @Patrick, I'm trying to do the same thing as you did back in '14, how did you end up get the image into the PDF before merging? What command did you use within PDFTK to merge the PDF with an image into the PDF with data? – Aaron Apr 30 '16 at 21:30

0 Answers0