Skip to content
Discussion options

You must be logged in to vote

Look at this snippet:

import fitz
from pprint import pprint
text = "Kleine Schwertwale bilden Schulen"
doc = fitz.open("text-oc.pdf")
page = doc[0]
rl = page.search_for(text)
assert len(rl) == 1
clip = rl[0]
# extract text info now - before the redacting removes it.
blocks = page.get_text("dict", clip=clip)["blocks"]
span = blocks[0]["lines"][0]["spans"][0]
assert span["text"] == text

# remove text
page.add_redact_annot(clip)
page.apply_redactions()

# re-insert same text - different color
font = fitz.Font("figo")  # this must be known somehow - or simply try some font else
tw = fitz.TextWriter(page.rect, color=(1, 0, 0))
# text insertion must use the original insertion poin and font size.

Replies: 7 comments 17 replies

Comment options

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

@JorjMcKie
Comment options

@qwertynik
Comment options

Comment options

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

@JorjMcKie
Comment options

@qwertynik
Comment options

@JorjMcKie
Comment options

@qwertynik
Comment options

Comment options

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

@qwertynik
Comment options

Answer selected by qwertynik
Comment options

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

Comment options

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

@JorjMcKie
Comment options

Comment options

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

Comment options

You must be logged in to vote
1 reply
@qwertynik
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