MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / test_insert

Function test_insert

tests/test_showpdfpage.py:16–31  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14
15
16def test_insert():
17 doc = pymupdf.open()
18 page = doc.new_page()
19 rect = pymupdf.Rect(50, 50, 100, 100) # insert in here
20 img = pymupdf.open(imgfile) # open image
21 tobytes = img.convert_to_pdf() # get its PDF version (bytes object)
22 src = pymupdf.open("pdf", tobytes) # open as PDF
23 xref = page.show_pdf_page(rect, src, 0, rotate=-23) # insert in rectangle
24 # extract just inserted image info
25 img = page.get_images(True)[0]
26 assert img[-1] == xref # xref of Form XObject!
27 img = page.get_image_info()[0] # read the page's images
28
29 # Multiple computations may have lead to rounding deviations, so we need
30 # some generosity here: enlarge rect by 1 point in each direction.
31 assert img["bbox"] in rect + (-1, -1, 1, 1)
32
33def test_2742():
34 dest = pymupdf.open()

Callers

nothing calls this directly

Calls 5

new_pageMethod · 0.80
convert_to_pdfMethod · 0.80
show_pdf_pageMethod · 0.80
get_imagesMethod · 0.80
get_image_infoMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…