Linked vs. Embedded Template Images

Hey, it has been a while since I wrote a blog entry.  I just spent a week visiting a customer site and getting familiar with a major form deployment.  Lots of learning happened in both directions.  And lots of stuff for me to report back on at this blog — starting today.

Images and PDF sizes

We do not support linked images from PDF files.  Remember, the "P" in PDF means "Portable".  If the file has references to external content, it isn’t exactly portable.  Another issue with linked images is that a PDF file with an external reference cannot reliably embed a digital signature.

In your XFA template you have the choice to link or embed images.  But the final PDF will always have the images embedded — even if the template referenced them with a link.

Given that, what factors do you consider when you choose whether to embed or link images in your XFA templates?  Choosing between the two has size implications in the generated PDF.  Here is a bit of detail on how they get processed:

Embedded Images

Embedded images are stored in the XFA template XML as a base64-encoded value.  As with all base64 encoded binary data, the size expands by a factor of 4/3.  When Adobe Reader renders a dynamic form, it extracts the image data from the template and draws it to the screen.  If a template embeds the same image multiple times, we carry all copies of the duplicated image in the template and consequently, inside the PDF.

Linked Images

When we create a PDF from an XFA template with linked images, the images are stored in a PDF resource area.  We create an indexed name for the image based on the image file reference.  There are two efficiencies gained here:

  1. The images are stored in binary format — not base64 encoded
  2. Multiple references to the same image are reconciled to a single copy of that image in the PDF

So clearly, if you are including images, and especially if you are including multiple copies of the same image in your XFA form, your final PDF will be smaller when you include those images as links instead of by embedding.

4 Responses to Linked vs. Embedded Template Images

  1. Thanks John for this!Our workflow doesn’t include generating PDFs from XFA templates, so I tend to embed images directly into the form.When I need to use the same image in multiple places in a form, in different x, y coordinates, I embed it once in a hidden image object.Then every time I need the image I use an imageField object with something similar in the docReady event:this.rawValue = embedImage.value.image.value;this.access = readOnly;I do this under the ASSUMPTION that because the image is only embedded once, that no matter how many times it is referenced, it will not balloon the file size.Would be interested in your views.Thanks,Niall

  2. Niall:Great question. In your case, I think what you’ll find is that the initial size of your form includes only one copy of the image, but after assigning multiple copies and saving the PDF you’ll find that the PDF size increases due to multiple embedded copies. This is because the form state will save the changes to the image objects you assign. Of course, if you’re not saving the PDF this won’t be an issue.Your alternative is to set up the image as a link and copy the value using:Image1.value.image.href = Image2.value.image.href;In this case, the form state storage will stay small.Good luck!John

  3. Bruce says:

    Hi John,I have just tried using the linked but not embedded approach to images and could see the difference in file sizes in a simple test form. But our real forms use lots of fragments and it appears that the same image used in each fragment is duplicated in the final PDF. At least the file size ends up being almost as big as if we had embedded the images.Does this sound likely or am I doing something else wrong.Bruce

  4. Bruce:Keep in mind that we use the image URL to determine whether two images are reconciled to the same copy in the PDF. Have a look at the href attribute in your fragments. If they’re the same, they should get combined to the same image reference. It is possible that if you have fragments in different directories that their relative references to the same image could be different.John