Can I change the page count by changing internal metadata?
Some days ago I started to play with the internal structure of PDF document. While searching the internet, I've found some nice tools to edit the metadata, so far I haven't found how (and if) I can edit the page count in a way it won't affect the way the PDF is visualized. Can I change some metadata field, so that I can see a "fake" page count? If so, how is it done? Where can I read more about the internal structure of a PDF document?
Posted on StackOverflow on Feb 11, 2015 by shalom shalom
The page count isn't stored anywhere inside a PDF, hence you can not set some value to fool people into believing that there aren't as many pages as there are.
You can read more about the internal structure of a PDF document in ISO-32000-1, but if you prefer a more practical approach, please download iText RUPS and take a look at the internal structure of a PDF.
I have opened a file with two pages in RUPS as an example:
RUPS Page tree view
As you can see, the /Catalog
dictionary (aka the root dictionary) of the PDF file has an entry named /Pages
. This is the root of the page tree.
This /Pages
entry has /Kids
that can either be another /Pages
dictionary (a branch of the page tree) or a /Page
dictionary (a leaf of the page tree). In this case, we see two /Page
elements.
A PDF viewer will traverse through the page tree and count the number of /Page
dictionaries to calculate the total page count.
If you want to change the page count, you can remove /Page
dictionaries, but that will also remove the pages. You can add /Page
dictionaries, but that will add pages.
The number of pages of a document isn't stored in metadata, hence your question to change the page count by changing some metadata is not a valid question.