Enabling and Disabling Annotations! #2229
Unanswered
Aadil-5122
asked this question in
Looking for help
Replies: 1 comment
-
This works as it should: import fitz
from PIL import Image
import io
doc = fitz.open()
page = doc.new_page()
r = fitz.Rect(100, 100, 300, 300)
text = """Some text to be visible,
to be visible depending on an
annotation overlaying it."""
# insert text and show the page
page.insert_textbox(r, text)
fp = io.BytesIO(page.get_pixmap().tobytes())
img = Image.open(fp)
img.show()
# cover text by white rect annot and show
a = page.add_rect_annot(r)
a.set_colors(fill=(1, 1, 1), stroke=(1, 1, 1))
a.update()
page = doc.reload_page(page)
fp = io.BytesIO(page.get_pixmap().tobytes())
img = Image.open(fp)
img.show()
# set annot to fully transparent and show again
a.set_opacity(0)
a.update()
page = doc.reload_page(page)
fp = io.BytesIO(page.get_pixmap().tobytes())
img = Image.open(fp)
img.show()
page = None
doc.close() |
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.
-
Good Evening Sir,
I want to cover/hide a text in a PDF and also, unhide/un-cover the same when needed,
I used a "rectangular annotation" for the same the code for which is as follows:
rect= (386.2793884277344, 711.2273559570312, 470.71710205078125, 723.1173095703125)
annot1= page.add_rect_annot(rect)
for unhiding:
annot1.set_colors(fill=None, stroke=None)
annot1.set_opacity(0)
annot1.update( )
page= doc.reload_page(page)
for hiding:
annot1.set_colors(fill=(1, 1, 1), stroke=(1, 1, 1))
annot1.set_opacity(1)
annot1.update()
page= doc.reload_page(page)
for again unhiding/un-covering:
annot1.set_colors(fill=None, stroke=None)
annot1.set_opacity(0)
annot1.update( )
page= doc.reload_page(page)
The Problem i am facing is that once i have hide the text (using above specified code), i am not able to see it (the text) when i try to unhide it (using the above specified code).
where am i going wrong?
Beta Was this translation helpful? Give feedback.
All reactions