Replacing bitmaps with PDF drawings/shapes #2155
-
Hi, Situation
Goal
From what I read in other discussions so far, one way might be to extract all individual shapes and texts from the "pdf images" and then commit and position them in the original file. However, I am wondering if there might be a more elegant way of inserting the whole "pdf image" as a whole. E.g. to not accidentially oversee some shapes while extracting. Any help is much appreciated :-) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Let me see if I got you.
So far correct? If yes:
Ad 1. & 2. from pprint imprt pprint
imglist = page.get_images()
pprint(imglist)
[(1114, 1126, 1200, 1200, 8, 'DeviceRGB', '', 'Im1', 'FlateDecode')]
# 1114 is the xref
# get the bbox of that image on the page:
pprint(page.get_image_rects(1114))
[Rect(240.00100708007812, 88.93600463867188, 540.0009765625, 388.9360046386719)]
# this is a list because same image may appear multiple times on a page
# so bbox=fitz.Rect(240.00100708007812, 88.93600463867188, 540.0009765625, 388.9360046386719) Ad 3. Delete bitmap: Ad 4. Insert the vector PDF page. Assuming page 0 of that PDF is the vector image: src = fitz.open("vector.pdf")
page.show_pdf_page(bbox, src, 0)
# that's it! If the vector image in vector.pdf does not cover the full page, but a sub-rectangle, say page.show_pdf_page(bbox, src, 0, clip=subrect) |
Beta Was this translation helpful? Give feedback.
Let me see if I got you.
So far correct?
If yes:
Ad 1. & 2.
Make a list of images of page n of thesis: