Skip to content

Option to clear all images from a page #2743

Answered by pubpub-zz
Soremwar asked this question in Q&A
Discussion options

You must be logged in to vote

you have 2 options:
a) you know which image is the one to replace:
eg:

from PIL import Image
(...)
page.image[0].replace(Image.open("image.jpg"))

b) you delete all images, then create new pdf using pillow , and merge pages placing the new one behind

from PIL import Image
(...)
page.remove_objects_from_page(page,ObjectDeletionFlag.XOBJECT_IMAGES)
img = Image.open("image.jpg")
b= BytesIO()
img.save(b,"pdf")
img_pdf = PdfReader(b)
img_page = img_pdf.pages[0]
page.merge_page(img_page,over=False)

PS: I convert this as a discussion as this not an issue

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by stefan6419846
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
Converted from issue

This discussion was converted from issue #2742 on July 08, 2024 18:27.