Skip to content
Discussion options

You must be logged in to vote

The following code snippet removes the red top-left image on the first page only:

import fitz
doc=fitz.open("example.pdf")
page=doc[0]
from pprint import pprint
pprint(page.get_images())
[(17, 0, 137, 55, 8, 'DeviceRGB', '', 'Im0', 'DCTDecode'),
 (18, 0, 405, 411, 8, 'DeviceRGB', '', 'Im1', 'DCTDecode')]

# check locations of the 2 images:
rects=page.get_image_rects(17)
rects  # this one is top-right
[Rect(492.7799987792969, 15.1199951171875, 580.3200073242188, 87.1199951171875)]

rects2=page.get_image_rects(18)
rects2  # this one is top-left:
[Rect(27.0, 16.55999755859375, 99.0, 88.55999755859375)]

page.add_redact_annot(rects2[0])  # cover top-left image with aredaction
'Redact' annotation

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

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

Answer selected by JorjMcKie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants