Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to extract texts between two coordinates in a page? #3955

Closed
StephenZKCurry opened this issue Oct 17, 2024 · 1 comment
Closed

How to extract texts between two coordinates in a page? #3955

StephenZKCurry opened this issue Oct 17, 2024 · 1 comment

Comments

@StephenZKCurry
Copy link

I want to extract texts between two coordinates on a page use the PDF's underlying flow of characters as a guide for ordering and segmenting the words, rather than presorting the characters by x/y position, mimics dragging a cursor highlights text in a PDF, How can I do that?

@JorjMcKie
Copy link
Collaborator

You can supply an arbitrary rectangle ("clip") inside which your desired text lives. If you only have top and bottom values, make a rectangle clip = pymupdf.Rect(0, top, page.rect.width, bottom).
Then execute text = page.get_text(sort=True, clip=clip).
This will (pymupdf v1.24.11+) extract the text in reading order.

@pymupdf pymupdf locked and limited conversation to collaborators Oct 17, 2024
@JorjMcKie JorjMcKie converted this issue into discussion #3959 Oct 17, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants