@@ -2010,3 +2010,44 @@ def test_4639():
20102010 with pymupdf .open (path ) as document :
20112011 page = document [- 1 ]
20122012 page .get_bboxlog (layers = True )
2013+
2014+
2015+ def test_4590 ():
2016+
2017+ # Create test PDF.
2018+ path = os .path .normpath (f'{ __file__ } /../../tests/test_4590.pdf' )
2019+ with pymupdf .open () as document :
2020+ page = document .new_page ()
2021+
2022+ # Add some text
2023+ text = 'This PDF contains a file attachment annotation.'
2024+ page .insert_text ((72 , 72 ), text , fontsize = 12 )
2025+
2026+ # Create a sample file.
2027+ path_sample = os .path .normpath (f'{ __file__ } /../../tests/test_4590_annotation_sample.txt' )
2028+ with open (path_sample , 'w' ) as f :
2029+ f .write ('This is a sample attachment file.' )
2030+
2031+ # Read file as bytes
2032+ with open (path_sample , 'rb' ) as f :
2033+ sample = f .read ()
2034+
2035+ # Define annotation position (rect or point)
2036+ annot_pos = pymupdf .Rect (72 , 100 , 92 , 120 ) # PushPin icon rectangle
2037+
2038+ # Add the file attachment annotation
2039+ page .add_file_annot (
2040+ point = annot_pos ,
2041+ buffer_ = sample ,
2042+ filename = 'sample.txt' ,
2043+ ufilename = 'sample.txt' ,
2044+ desc = 'A test attachment file.' ,
2045+ icon = 'PushPin' ,
2046+ )
2047+
2048+ # Save the PDF
2049+ document .save (path )
2050+
2051+ # Check pymupdf.Document.scrub() works.
2052+ with pymupdf .open (path ) as document :
2053+ document .scrub ()
0 commit comments