Skip to content
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

ENH: add UniGB-UTF16 encodings #2819

Merged
merged 1 commit into from
Aug 28, 2024
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
2 changes: 2 additions & 0 deletions pypdf/_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def build_char_map_from_dict(
"/ETenms-B5-V": "cp950",
"/UniCNS-UTF16-H": "utf-16-be",
"/UniCNS-UTF16-V": "utf-16-be",
"/UniGB-UTF16-H": "gb18030",
"/UniGB-UTF16-V": "gb18030",
# UCS2 in code
}

Expand Down
14 changes: 12 additions & 2 deletions tests/test_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ def test_eten_b5():
reader.pages[0].extract_text().startswith("1/7 \n富邦新終身壽險")


@pytest.mark.enable_socket()
def test_missing_entries_in_cmap():
"""
Issue #2702: this issue is observed on damaged pdfs
Expand All @@ -231,10 +230,21 @@ def test_missing_entries_in_cmap():


def test_null_missing_width():
"""For coverage of 2792"""
"""For coverage of #2792"""
writer = PdfWriter(RESOURCE_ROOT / "crazyones.pdf")
page = writer.pages[0]
ft = page["/Resources"]["/Font"]["/F1"]
ft[NameObject("/Widths")] = ArrayObject()
ft["/FontDescriptor"][NameObject("/MissingWidth")] = NullObject()
page.extract_text()


@pytest.mark.enable_socket()
def test_unigb_utf16():
"""Cf #2812"""
url = (
"https://github.com/user-attachments/files/16767536/W020240105322424121296.pdf"
)
name = "iss2812.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
assert "《中国能源展望 2060(2024 年版)》编写委员会" in reader.pages[1].extract_text()
Loading