Skip to content

Jules - two fixes and a simplification. #4528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20635,7 +20635,10 @@ def apply_pages(
initfn(*initfn_args, **initfn_kwargs)
ret = list()
document = Document(path)
for page in document:
if pages is None:
pages = range(len(document))
for pno in pages:
page = document[pno]
r = pagefn(page, *pagefn_args, **initfn_kwargs)
ret.append(r)

Expand Down
2 changes: 1 addition & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ def get_acroform(doc):
parents[xref]["new_xref"] = parent_xref_new
parents[xref]["new_kids"] = kids_xrefs_new

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

Expand Down
Binary file added tests/resources/test_4412.pdf
Binary file not shown.
12 changes: 2 additions & 10 deletions tests/test_4520.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@

def test_4520():
"""Accept source pages without /Contents object in show_pdf_page."""
vsn_tuple = tuple(map(int, pymupdf.__version__.split(".")))
tar = pymupdf.open()
src = pymupdf.open()
src.new_page()
page = tar.new_page()
try:
assert page.show_pdf_page(page.rect, src, 0)
rc = True
except Exception as e:
rc = False
if vsn_tuple < (1, 26, 0):
assert rc is False
else:
assert rc is True
xref = page.show_pdf_page(page.rect, src, 0)
assert xref
16 changes: 16 additions & 0 deletions tests/test_insertpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,19 @@ def test_merge_checks2():

assert len(set(names0 + names1)) == len(names2)
assert kids2 == dup_kids


test_4412_path = os.path.normpath(f'{__file__}/../../tests/resources/test_4412.pdf')

def test_4412():
# This tests whether a page from a PDF containing widgets found in the wild
# can be inserted into a new document with default options (widget=True)
# and widget=False.
print()
for widget in True, False:
print(f'{widget=}', flush=1)
with pymupdf.open(test_4412_path) as doc, pymupdf.open() as new_doc:
buf = io.BytesIO()
new_doc.insert_pdf(doc, from_page=1, to_page=1)
new_doc.save(buf)
assert len(new_doc)==1
11 changes: 11 additions & 0 deletions tests/test_textextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,17 @@ def llen(texts):
pymupdf._log_items_clear()


def test_4524():
path = os.path.abspath(f'{__file__}/../../tests/resources/mupdf_explored.pdf')
print('')
document = pymupdf.Document(path)
texts_single = pymupdf.get_text(path, method='single', pages=[1, 3, 5])
texts_mp = pymupdf.get_text(path, method='mp', pages=[1, 3, 5])
print(f'{len(texts_single)=}')
print(f'{len(texts_mp)=}')
assert texts_mp == texts_single


def test_3594():
verbose = 0
print()
Expand Down