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="">
<FFGraphic1 xfa:contentType="image/jpeg" href="C:\Sample.jpg"></FFGraphic1>
  • Embedded
<image xmlns:xfa="">
<FFGraphic1 xfa:contentType="image/tiff" xfa:transferEncoding="base64">

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"?>
	 <field name="FFGraphic1" y="35.56mm" x="81.28mm" w="91.55mm" h="68.53mm" access="protected">