People often ask how you can have a broken PDF file? I have looked at a file which gives a nice example so here is an explanation.
When you load a PDF file, it has lots of pointers. If the file is linearized, it will have a hints table (/H) telling you the location of the Linearization data in the file. Here is an example from the start of this PDF file.
%PDF-1.5% 915 0 obj<< /Linearized 1 /H [5844 584] /O 954 /E 61736 /N 7 /L 180360 /T 161941>> endobj
So far so good, we go to offset 5844 (which is 16D4 in hex) and read the object which starts there. Except, the H object does not start there – it starts at 1671 hex. Here is it viewed in a hex editor.
The value set puts us in the middle of a random binary data stream (which is going to be very confusing for any PDF parser). So in this case we abandon any attempt to open the PDF in linearized mode. If you open it in Adobe it will tell you it is broken and try to fix it.
Wrong links in PDF files and a major cause of PDF files being ‘broken’ because they point to random data when something is expected.
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!
Latest posts by Mark Stephens (see all)
- How we are improving our code quality with IDEA in 2018 - March 7, 2018
- How we are improving our code quality with NetBeans in 2018 - March 1, 2018
- 3 ways that the European Union is changing the way Companies write software in 2018 - January 31, 2018
- IDRsolutions product range update for 2018 - January 22, 2018
- 4 ways Companies can make remote working successful - December 21, 2017