How might I get information (specifically, area) about vector shapes using Python?

46 Views Asked by At

I'll cut the preamble.

In a perfect world, I'd have a script with which I can parse a PDF, grab all vector shapes of a given description (stroke colour would be ideal in this scenario but I may be able to make do with something else), add up their combined area and compare that to the area of the bounding box of the PDF file itself.

Note that these paths are not guaranteed to be regular shapes. Some will contain curved sections, so it won't be a case of width*height=area2, sadly.

I have found a way of grabbing the width and height of the PDF file itself, but have not yet found a way to evaluate vector paths, find the one (or ones) with x criteria and calculate their area.

I've researched various modules including PyPDF, pdfminer and pdfreader, but from the descriptions given, they don't seem to offer a way to look at vector paths. I've found ways to parse and read text, but not vector shapes.

Edit: Excuse me, I should've elaborated more explicitly that my end goal from comparing the size of these shapes to the size of the PDF is so that I can get a percentage reading of how much of the PDF is taken up by the shape or shapes.

0

There are 0 best solutions below