Skip to content

Commit

Permalink
ROB: Missing basefont entry in type 3 font (#2469)
Browse files Browse the repository at this point in the history
closes #2289
  • Loading branch information
pubpub-zz authored Feb 25, 2024
1 parent 03af2c2 commit af36667
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pypdf/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -2340,7 +2340,10 @@ def process_font(f: DictionaryObject) -> None:
)
):
# the list comprehension ensures there is FontFile
emb.add(cast(str, f["/BaseFont"]))
try:
emb.add(cast(str, f["/BaseFont"]))
except KeyError:
emb.add("(" + cast(str, f["/Subtype"]) + ")")

if "/DR" in obj and "/Font" in cast(DictionaryObject, obj["/DR"]):
for f in cast(DictionaryObject, cast(DictionaryObject, obj["/DR"])["/Font"]):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -1398,3 +1398,12 @@ def visitor_lvl(text, cm, tm, fontdict, fontsize) -> None:
"hotels, short-term rentals, etc., advertised rates: mandatory fee disclosures, SB 683",
"housing rental properties advertised rates: disclosures, SB 611",
]


@pytest.mark.enable_socket()
def test_missing_basefont_in_type3():
"""Cf #2289"""
url = "https://github.com/py-pdf/pypdf/files/13307713/missing-base-font.pdf"
name = "missing-base-font.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
reader.pages[0]._get_fonts()

0 comments on commit af36667

Please sign in to comment.