Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Making sure Image names are unique in PDF files

57 sec read

All images have a name in the PDF image XObject, usually along the lines of IM0, IM1, IM2, etc. This is unique for each page, so there will be only one Im0 on each page.

If the PDF page contains XForm objects, they can also contain images. These need to be unique for the XForm, but can be the same as a value used on a page. Similarly, the XForm can contain XForms with their own images, and so forth. So you could have this situation.

Main page with images Im0, Im1, Im2, Im3 and XForm XF1. This could have images Imo, Im1, Im2 another XForm with yet more images.

I was recently caught out by this because I was using the image name (Im0) as a key (I should have been using something like Im0, XF1.Im0 and XF1.XF1.Im0 to provide unique keys.

The name is used to reference to Images in the Resources object. In this case, each XForm has its own unique resources object (or uses the global resources), so Im0 works correctly in this context.

So you need to be careful with names in PDF files. You have a similar issue with Forms name, where sometimes you use just the Form name and any inherited values from its parent. But that is for another article…

This post is part of our “Understanding the PDF File Format” series. In each article, we discuss a PDF feature, bug, gotcha or tip. If you wish to learn more about PDF, we have 13 years worth of PDF knowledge and tips, so click here to visit our series index!

Did you know...

IDRsolutions offers a whole range of online file converters to convert PDF and Microsoft Excel, Word and Office Documents to HTML5, SVG or image formats?

It is free to use for single file conversions and also includes Developer links if you want to use our commercial software for bulk conversions. Find out more on this page

Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

How to read HEIC image files in Java with…

In this article, I will explain how to read HEIC files into Java as a BufferedImage. ImageIO does not read HEIC file types so...
Mark Stephens
1 min read

How to convert WMF files to SVG in java…

This article will show you how to convert WMF files into SVG files using our JDeli Java Image library. What is WMF? WMF is...
Amy Pearson
1 min read

How to write WebP images in Java

In this article, I will walk you through how to write out images as WebP images in Java. ImageIO does not support WebP images...
Mark Stephens
1 min read

Leave a Reply

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

IDRsolutions Ltd 2020. All rights reserved.