Skip to content
Closed
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
38 changes: 23 additions & 15 deletions tests/test_4141.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import pymupdf

import os.path
from pathlib import Path


def test_4141():
"""survive missing /Resources object in a number of cases."""
path = os.path.abspath(f"{__file__}/../../tests/resources/test_4141.pdf")
doc = pymupdf.open(path)
page = doc[0]
# make sure the right test file
assert doc.xref_get_key(page.xref, "Resources") == ("null", "null")
page.insert_htmlbox((100, 100, 200, 200), "Hallo") # will fail without the fix
doc.close()
doc = pymupdf.open(doc.name)
page = doc[0]
tw = pymupdf.TextWriter(page.rect)
tw.append((100, 100), "Hallo")
tw.write_text(page) # will fail without the fix
"""Survive missing /Resources object in multiple situations."""

# Resolve the test file path
test_pdf = Path(__file__).resolve().parent.parent / "tests" / "resources" / "test_4141.pdf"
assert test_pdf.exists(), f"Missing test file: {test_pdf}"

# Case 1: Insert HTML box
with pymupdf.open(test_pdf) as doc:
page = doc[0]

# Ensure we are using the correct test file
assert doc.xref_get_key(page.xref, "Resources") == ("null", "null")

# Should not fail after the fix
page.insert_htmlbox((100, 100, 200, 200), "Hallo")

# Case 2: TextWriter operations after reopen
with pymupdf.open(test_pdf) as doc:
page = doc[0]
tw = pymupdf.TextWriter(page.rect)
tw.append((100, 100), "Hallo")
tw.write_text(page) # Should also not fail
Loading