Skip to content

How to determine which object is "on top" #694

Answered by jsvine
bpugnaire asked this question in Q&A
Discussion options

You must be logged in to vote

I believe that the PDF Reference specifies that objects are drawn on top of one another, in the order that the document creates them. And I believe that pdfminer.six extracts objects in that same order. So for two rectangles, the "top" one would be the rectangle that appears later in page.rects than the other. Does that seem to be the case for your PDF?

For two objects of the same pdfminer.six type (e.g., two rects, two lines, two chars), the comparison should be easy. But if you're comparing across types (e.g., a rect vs. a line), you'll want to run something like ordered_objects = list(page.iter_layout_objects(page.layout._objs)) and then do the comparison based on that list.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@bpugnaire
Comment options

Answer selected by bpugnaire
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants