Merging image data into a XFA template

There are many cases when a user may need to specify the image contents via a data file. Let’s take a simple hypothetical example. Say you are a company that specializes in printing purchase order forms for a number of customers. The form is designed once and it’s the data merged into the form that dictates the final format. Part of the data loaded in could be the customers company’s logo.

The Data File

or an image, there are two ways to specify the content.

  • Link
<image xmlns:xfa="http://www.xfa.com/schema/xfa-data">
<FFGraphic1 xfa:contentType="image/jpeg" href="C:\Sample.jpg"></FFGraphic1>
</image>
  • Embedded
<image xmlns:xfa="http://www.xfa.com/schema/xfa-data">
<FFGraphic1 xfa:contentType="image/tiff" xfa:transferEncoding="base64">
SUkqAAgAAAASAP4ABAABAAAAAAAAAAABAwABAAAAqQAAAAEBAwABAAAAwgAAAAIBAwADAAAApAIA
AAMBAwABAAAAAQAAAAYBAwABAAAAAgAAAAoBAwABAAAAAQAAABEBBAAEAAAAQIMBABIBAwABAAAA
...
AMp6AADKegAA2A8AAPgCAADCfQAAjPgAAFZzAQA=
</FFGraphic1>
</image>

In both cases the contentType attribute MUST be specified. If not specified, it will default to ‘text/plain’ and likely result is that the image will not be rendered. During the merge process, the contentType of the data is overrides the contentType specified in the template in order to coerce the field to the data contentType.

Note the xfa: namespace prefix is required for the contentType and transferEncoding attributes.

The Template File

<?xml version="1.0" encoding="UTF-8"?>
<?xfa generator="FF99V40" APIVersion="4.0.4200.2002"?>
<xfa>
 <template>
	 ...
	 <field name="FFGraphic1" y="35.56mm" x="81.28mm" w="91.55mm" h="68.53mm" access="protected">
	  <value>
		<image/>
	  </value>
	  <ui>
		<defaultUi/>
	  </ui>
	 </field>
	 ...
 </template>
</xfa>

One Response to Merging image data into a XFA template

  1. Chris says:

    This looks great!
    But where to download a XFA temp?

Leave a Reply

Your email address will not be published. Required fields are marked *


4 − two =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>