Skip to content
Discussion options

You must be logged in to vote

It is of no importance, from where you get the bbox whose background color you need.
My code above only shows how to avoid the fairly confusing handling of page rotations. But you can also do this:

import fitz
from pprint import pprint

doc = fitz.open("bookmarks.pdf")
page = doc[0]
pix = page.get_pixmap()
blocks = page.get_text("dict")["blocks"]
for b in blocks:
    for l in b["lines"]:
        for s in l["spans"]:
            if s["text"] == "Lawrence of Arabia":
                # adjust bbox to pixmap coordinates:
                bbox = fitz.Rect(s["bbox"]) * page.rotation_matrix
                pprint(pix.color_topusage(clip=bbox))
                print()

Replies: 3 comments 9 replies

Comment options

You must be logged in to vote
4 replies
@JorjMcKie
Comment options

@JorjMcKie
Comment options

@meghanaviyyapu
Comment options

@JorjMcKie
Comment options

Comment options

You must be logged in to vote
2 replies
@JorjMcKie
Comment options

Answer selected by JorjMcKie
@meghanaviyyapu
Comment options

Comment options

You must be logged in to vote
3 replies
@JorjMcKie
Comment options

@meghanaviyyapu
Comment options

@JorjMcKie
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants