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

Function test_4590

tests/test_general.py:2058–2096  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2056
2057
2058def test_4590():
2059
2060 # Create test PDF.
2061 path = os.path.normpath(f'{__file__}/../../tests/test_4590.pdf')
2062 with pymupdf.open() as document:
2063 page = document.new_page()
2064
2065 # Add some text
2066 text = 'This PDF contains a file attachment annotation.'
2067 page.insert_text((72, 72), text, fontsize=12)
2068
2069 # Create a sample file.
2070 path_sample = os.path.normpath(f'{__file__}/../../tests/test_4590_annotation_sample.txt')
2071 with open(path_sample, 'w') as f:
2072 f.write('This is a sample attachment file.')
2073
2074 # Read file as bytes
2075 with open(path_sample, 'rb') as f:
2076 sample = f.read()
2077
2078 # Define annotation position (rect or point)
2079 annot_pos = pymupdf.Rect(72, 100, 92, 120) # PushPin icon rectangle
2080
2081 # Add the file attachment annotation
2082 page.add_file_annot(
2083 point = annot_pos,
2084 buffer_ = sample,
2085 filename = 'sample.txt',
2086 ufilename = 'sample.txt',
2087 desc = 'A test attachment file.',
2088 icon = 'PushPin',
2089 )
2090
2091 # Save the PDF
2092 document.save(path)
2093
2094 # Check pymupdf.Document.scrub() works.
2095 with pymupdf.open(path) as document:
2096 document.scrub()
2097
2098
2099def test_4702():

Callers

nothing calls this directly

Calls 6

new_pageMethod · 0.80
add_file_annotMethod · 0.80
scrubMethod · 0.80
insert_textMethod · 0.45
writeMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…