Skip to content

Commit 40da3b0

Browse files
committed
Address missing /Resources object
Intercept missing page resources
1 parent 4c27c50 commit 40da3b0

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8313,6 +8313,8 @@ def _show_pdf_page(self, fz_srcpage, overlay=1, matrix=None, xref=0, oc=0, clip=
83138313
# 1. insert Xobject in Resources
83148314
#-------------------------------------------------------------
83158315
resources = mupdf.pdf_dict_get_inheritable(tpageref, PDF_NAME('Resources'))
8316+
if not resources.m_internal:
8317+
resources = mupdf.pdf_dict_put_dict(tpageref,PDF_NAME('Resources'),5)
83168318
subres = mupdf.pdf_dict_get(resources, PDF_NAME('XObject'))
83178319
if not subres.m_internal:
83188320
subres = mupdf.pdf_dict_put_dict(resources, PDF_NAME('XObject'), 5)
@@ -16820,6 +16822,8 @@ def JM_merge_resources( page, temp_res):
1682016822
'''
1682116823
# page objects /Resources, /Resources/ExtGState, /Resources/Font
1682216824
resources = mupdf.pdf_dict_get(page.obj(), PDF_NAME('Resources'))
16825+
if not resources.m_internal:
16826+
resources = mupdf.pdf_dict_put_dict(page.obj(), PDF_NAME('Resources'),5)
1682316827
main_extg = mupdf.pdf_dict_get(resources, PDF_NAME('ExtGState'))
1682416828
main_fonts = mupdf.pdf_dict_get(resources, PDF_NAME('Font'))
1682516829

tests/resources/test_4141.pdf

3.39 KB
Binary file not shown.

tests/test_4141.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pymupdf
2+
3+
import os.path
4+
5+
6+
def test_4141():
7+
"""survive missing /Resources object in a number of cases."""
8+
path = os.path.abspath(f"{__file__}/../../tests/resources/test_4141.pdf")
9+
doc = pymupdf.open(path)
10+
page = doc[0]
11+
# make sure the right test file
12+
assert doc.xref_get_key(page.xref, "Resources") == ("null", "null")
13+
page.insert_htmlbox((100, 100, 200, 200), "Hallo") # will fail without the fix
14+
doc.close()
15+
doc = pymupdf.open(doc.name)
16+
page = doc[0]
17+
tw = pymupdf.TextWriter(page.rect)
18+
tw.append((100, 100), "Hallo")
19+
tw.write_text(page) # will fail without the fix

0 commit comments

Comments
 (0)