3 ms·
Some time ago I came to a similar conclusion: In most cases, the only way to properly process PDF files is to render them and work on the raster images. I was
by vog 9y ago
Some time ago I came to a similar conclusion: In most cases, the only way to properly process PDF files is to render them and work on the raster images.
I was involved in a project where we needed to determine the final size of an image in a PDF document.
This seemed simple: Just keep track of all transformation matrices applied to the image, then calculate the final size.
But we underestimated the nonsense complexity of PDF: The image could be a real image or an embedded EPS, which are completely different cases. The image could have inner transparency, but could can also have an outer alpha mask by the PDF document. Then there are clipping paths, but be aware of the always implicitly present clipping path that is the page boundary. Oh, and an image may be overlapped by text, or even another image, in which case you need to to the same processing for that one, too. And so on.
After wasting lots of time almost rebuilding a PDF renderer accidentally, we decided to use an existing renderer instead.
Turned out the only feasible solution was to render the PDF twice: with and without the image, and to compare the results pixel by pixel.
I'm afraid the modern web might develop in a similar direction.