Skip to content

Commit c469893

Browse files
src/ tests/: fix bug in insert_pdf(), #4412.
tests/: add reproducer test_4412(). src/utils.py: fix iteration in do_widgets().
1 parent 9a2ab91 commit c469893

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,7 @@ def get_acroform(doc):
19491949
parents[xref]["new_xref"] = parent_xref_new
19501950
parents[xref]["new_kids"] = kids_xrefs_new
19511951

1952-
for i in src_range:
1952+
for i in range(len(src_range)):
19531953
# read first copied over page in target
19541954
tar_page = tar[start_at + i]
19551955

tests/resources/test_4412.pdf

1.33 MB
Binary file not shown.

tests/test_insertpdf.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,19 @@ def test_merge_checks2():
298298

299299
assert len(set(names0 + names1)) == len(names2)
300300
assert kids2 == dup_kids
301+
302+
303+
test_4412_path = os.path.normpath(f'{__file__}/../../tests/resources/test_4412.pdf')
304+
305+
def test_4412():
306+
# This tests whether a page from a PDF containing widgets found in the wild
307+
# can be inserted into a new document with default options (widget=True)
308+
# and widget=False.
309+
print()
310+
for widget in True, False:
311+
print(f'{widget=}', flush=1)
312+
with pymupdf.open(test_4412_path) as doc, pymupdf.open() as new_doc:
313+
buf = io.BytesIO()
314+
new_doc.insert_pdf(doc, from_page=1, to_page=1)
315+
new_doc.save(buf)
316+
assert len(new_doc)==1

0 commit comments

Comments
 (0)