Replies: 2 comments 1 reply
-
Your code should work actually. At least at first sight.
The PDF must be corrupt.Try to repair first before you do your stuff. E.g. mutool clean -ggggz file.pdf.
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
From: Amir ***@***.***>
Sent: Montag, 12. Juli 2021 03:00
To: ***@***.***>
Cc: ***@***.***>
Subject: [pymupdf/PyMuPDF] How to highlight multiple keywords ? (#1139)
I want to highlight all occurrences of multiple keywords. first i thought of highlighting all occurrences of one word and saving then overwriting the same file for highlighting the next word. But, when i implemented that i was facing a file locking issue. My next approach is to search for all the keywords on the single page so here's my code
pdf = fitz.open(pdfFile)
for keyword in keywords:
for page in pdf:
text_instances = page.searchFor(keyword)
if len(text_instances) > 0:
for inst in text_instances:
highlight = page.addHighlightAnnot(inst)
highlight.setColors(stroke=(1, 0, 0))
highlight.update()
foundDocList.append(pdfFile)
pdf.save(f"{foundDocumentPath}/{os.path.splitext(os.path.basename(pdfFile))[0]}.pdf", garbage=4, deflate=True, clean=True)
but after implementing this i am getting this error mupdf: object out of range (21 0 R); xref size 21
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<#1139>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AB7IDITZLBXOUUYXTMIUJS3TXKHHPANCNFSM5AGGYPAQ>.
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Cannot reproduce. for this PDF >>> keywords
['pixmap', 'alpha', 'pymupdf']
>>> for kw in keywords:
for page in doc:
rl = page.search_for(kw)
for r in rl:
page.add_highlight_annot(r) Everything works fine: As an aside: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to highlight all occurrences of multiple keywords. first i thought of highlighting all occurrences of one word and saving then overwriting the same file for highlighting the next word. But, when i implemented that i was facing a file locking issue. My next approach is to search for all the keywords on the single page and then highlight it. So, here's my code
but after implementing this i am getting this error
mupdf: object out of range (21 0 R); xref size 21
Beta Was this translation helpful? Give feedback.
All reactions