如何在PDF规范中说明图像属于哪个页面?

I'm doing some low-level extracting of images directly out of a PDF file with PHP, since GhostScript is too slow, and I'm doing pretty well. But the problem is that I can't figure out where it says which page an image belongs to. I have no problem getting the images out of the PDF, but I'm having trouble figuring out the order of them.

Where in the PDF data does it say what page an image is supposed to be displayed on?

Images are stored in a PDF as standalone objects. They are referenced from a page through the page's Resources dictionary, XObject subdictionary. The relation is page -> resources -> images, so in order to know to what page an image belongs to you have to scan all the resource dictionaries of all the pages and see in which resources dictionary your image appears. An image can be referenced from multiple resource dictionaries. This is very low level PDF manipulation, I do not know how low level are you working in your code.