MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / test_3140

Function test_3140

tests/test_general.py:983–1013  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

981 archive = pymupdf.Archive(p)
982
983def test_3140():
984 css2 = ''
985 path = os.path.abspath(f'{__file__}/../../tests/resources/2.pdf')
986 oldfile = os.path.abspath(f'{__file__}/../../tests/test_3140_old.pdf')
987 newfile = os.path.abspath(f'{__file__}/../../tests/test_3140_new.pdf')
988 import shutil
989 shutil.copy2(path, oldfile)
990 def next_fd():
991 fd = os.open(path, os.O_RDONLY)
992 os.close(fd)
993 return fd
994 fd1 = next_fd()
995 with pymupdf.open(oldfile) as doc: # open document
996 page = doc[0]
997 rect = pymupdf.Rect(130, 400, 430, 600)
998 CELLS = pymupdf.make_table(rect, cols=3, rows=5)
999 shape = page.new_shape() # create Shape
1000 for i in range(5):
1001 for j in range(3):
1002 qtext = "<b>" + "Ques #" + str(i*3+j+1) + ": " + "</b>" # codespell:ignore
1003 atext = "<b>" + "Ans:" + "</b>" # codespell:ignore
1004 qtext = qtext + '<br>' + atext
1005 shape.draw_rect(CELLS[i][j]) # draw rectangle
1006 page.insert_htmlbox(CELLS[i][j], qtext, css=css2, scale_low=0)
1007 shape.finish(width=2.5, color=pymupdf.pdfcolor["blue"], )
1008 shape.commit() # write all stuff to the page
1009 doc.subset_fonts()
1010 doc.ez_save(newfile)
1011 fd2 = next_fd()
1012 assert fd2 == fd1, f'{fd1=} {fd2=}'
1013 os.remove(oldfile)
1014
1015def test_cli():
1016 if os.environ.get('PYODIDE_ROOT'):

Callers

nothing calls this directly

Calls 9

next_fdFunction · 0.85
new_shapeMethod · 0.80
insert_htmlboxMethod · 0.80
subset_fontsMethod · 0.80
ez_saveMethod · 0.80
removeMethod · 0.80
draw_rectMethod · 0.45
finishMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…