-1

I have tried:

from PyPDF2 import PdfReader

input_pdf = PdfReader(open("pdfFile.pdf", "rb"))
thispage = input_pdf.pages[0]
print(thispage.extract_text())

And I got the following error:

Traceback (most recent call last):
  File "C:\Users\Usuario\Desktop\pypdf.py", line 5, in <module>
    print(thispage.extract_text())
  File "C:\Users\Usuario\AppData\Local\Programs\Python\Python310\lib\site-packages\PyPDF2\_page.py", line 1851, in extract_text
    return self._extract_text(
  File "C:\Users\Usuario\AppData\Local\Programs\Python\Python310\lib\site-packages\PyPDF2\_page.py", line 1342, in _extract_text
    cmaps[f] = build_char_map(f, space_width, obj)
  File "C:\Users\Usuario\AppData\Local\Programs\Python\Python310\lib\site-packages\PyPDF2\_cmap.py", line 28, in build_char_map
    map_dict, space_code, int_entry = parse_to_unicode(ft, space_code)
  File "C:\Users\Usuario\AppData\Local\Programs\Python\Python310\lib\site-packages\PyPDF2\_cmap.py", line 196, in parse_to_unicode
    process_rg, process_char, multiline_rg = process_cm_line(
  File "C:\Users\Usuario\AppData\Local\Programs\Python\Python310\lib\site-packages\PyPDF2\_cmap.py", line 264, in process_cm_line
    multiline_rg = parse_bfrange(l, map_dict, int_entry, multiline_rg)
  File "C:\Users\Usuario\AppData\Local\Programs\Python\Python310\lib\site-packages\PyPDF2\_cmap.py", line 278, in parse_bfrange
    nbi = max(len(lst[0]), len(lst[1]))
IndexError: list index out of range

This happens only with a specific pdf file that is NOT encrypted. I could get it text with pdfminer but I read that it is slower so I want to use pypdf2 Do anyone know the solution?

1 Answers1

0

PyPDF2 is deprecated. Use pypdf. The issue is solved:

https://github.com/py-pdf/pypdf/issues/1533

I'm the maintainer is PyPDF2 and pypdf.

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958