Skip to content

Commit

Permalink
BUG: Use the correct name StandardEncoding for the predefined cmap (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan6419846 authored Feb 26, 2025
1 parent 0714711 commit f65245f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pypdf/_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ def _parse_encoding(
f"Advanced encoding {encoding} not implemented yet",
__name__,
)
encoding = charset_encoding["/StandardCoding"].copy()
encoding = charset_encoding["/StandardEncoding"].copy()
else:
encoding = charset_encoding["/StandardCoding"].copy()
encoding = charset_encoding["/StandardEncoding"].copy()
if "/Differences" in enc:
x: int = 0
o: Union[int, str]
Expand Down
2 changes: 1 addition & 1 deletion pypdf/_codecs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def rev_encoding(enc: List[str]) -> Dict[str, int]:


charset_encoding: Dict[str, List[str]] = {
"/StandardCoding": _std_encoding,
"/StandardEncoding": _std_encoding,
"/WinAnsiEncoding": _win_encoding,
"/MacRomanEncoding": _mac_encoding,
"/PDFDocEncoding": _pdfdoc_encoding,
Expand Down
12 changes: 12 additions & 0 deletions tests/test_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,15 @@ def test_binascii_odd_length_string(caplog):
page = reader.pages[0]
assert "\n(Many other theorems may\n" in page.extract_text()
assert "Skipping broken line b'143f 143f 10300': Odd-length string\n" in caplog.text


@pytest.mark.enable_socket
def test_standard_encoding(caplog):
"""Tests for #3156"""
url = "https://github.com/user-attachments/files/18983503/standard-encoding.pdf"
name = "issue3156.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))

page = reader.pages[0]
assert page.extract_text() == "Lorem ipsum"
assert "Advanced encoding" not in caplog.text

0 comments on commit f65245f

Please sign in to comment.