Intriguing PDF xref issue

I had a really intriguing PDF issue today. I was sent a PDF which did not open in JPedal but opens in Acrobat. It was allegedly created in Quartz. So I sat down to debug it….

Here is the start uncompressed xref table from a PDF file

xref
0 271
0000000000 65535 f
0000000015 00000 n
0000000102 00000 n
0000000178 00000 n
It contains 271 objects, and the first object (0) is ignored. Then object 1 starts at offset 15 and so on.

xref
0 47
0000000000 65535 f
0000089923 00000 n
0000089809 00000 n
0000088105 00000 n
0000087885 00000 n

So this xref table from the broken PDF contains 47 objects, and the first object (0) is ignored. Then object 1 starts at offset 89923 and it does not open. So I had a look at offset 89923 and it contains object zero!

0 0 obj <</Filter /FlateDecode /Length 1619>>stream

It is not object 1, it is object 0… Altering the offsets to start with 0 and not 1 fixed the file and it now opens. So we have to validate the first value and not trust the xref table to be correct. Be warned…

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!

Related Posts:

  • No Related Posts
The following two tabs change content below.

Mark Stephens

System Architect and Lead Developer at IDRSolutions
Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.
Markee174

About Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Leave a Reply

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

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=""> <s> <strike> <strong>