For some PDF files, I am receiving invalid characters as part of the text extraction, especially when ligatures are involved.
Please note that the direct goal of this issue is not to resolve #3376, which could be useful here, but analyze the issue with the font/ligature and possibly fix it.
Environment
Which environment were you using when you encountered the problem?
$ python -m platform
Linux-6.4.0-150600.23.103-default-x86_64-with-glibc2.38
$ python -c "import pypdf;print(pypdf._debug_versions)"
pypdf==6.16.1, crypt_provider=('cryptography', '46.0.5'), PIL=12.1.0
Code + PDF
This is a minimal, complete example that shows the issue:
from pypdf import PdfReader
reader = PdfReader('BSI-TR-03183-1_v1_0_0.pdf')
for index, page in enumerate(reader.pages):
if index not in {2, 3}:
continue
print(page)
print(page.get_contents().get_data())
print(page.extract_text().encode())
print(page.extract_text(extraction_mode="layout"))
The file is available at https://www.bsi.bund.de/SharedDocs/Downloads/EN/BSI/Publications/TechGuidelines/TR03183/BSI-TR-03183-1_v1_0_0.pdf?__blob=publicationFile&v=3
Traceback
There is no traceback, but the first extracted text is:
Technical Guideline TR-03183-1\nFederal Of\xee\x80\x80ce for Information Security 3
The wrongly interpreted text looks like this if printed as string instead of bytes:
Federal Ofce for Information Security
For some PDF files, I am receiving invalid characters as part of the text extraction, especially when ligatures are involved.
Please note that the direct goal of this issue is not to resolve #3376, which could be useful here, but analyze the issue with the font/ligature and possibly fix it.
Environment
Which environment were you using when you encountered the problem?
Code + PDF
This is a minimal, complete example that shows the issue:
The file is available at https://www.bsi.bund.de/SharedDocs/Downloads/EN/BSI/Publications/TechGuidelines/TR03183/BSI-TR-03183-1_v1_0_0.pdf?__blob=publicationFile&v=3
Traceback
There is no traceback, but the first extracted text is:
The wrongly interpreted text looks like this if printed as string instead of bytes: