python PyPDF2.utils.PdfReadError: Illegal character in Name Object
环境说明
PyCharm 2020.2.3 x64
Python 3.7
PyPDF2模块
报错场景
在使用PyPDF2模块将一个PDF文件分割成多个PDF文件时,出现报错
python PyPDF2.utils.PdfReadError: Illegal character in Name Object
报错原因
该错误是由于读取的PDF文件中包含多种编码导致
报错信息如下
Traceback (most recent call last):
File "E:\Program_Practice\Python\pachong\venv\lib\site-packages\PyPDF2\generic.py", line 484, in readFromStream
return NameObject(name.decode('utf-8'))
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcb in position 8: invalid continuation byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:/Program_Practice/Python/pachong/test/Day_12/pdf_segmentation.py", line 19, in <module>
pdf_writer.write(out)
File "E:\Program_Practice\Python\pachong\venv\lib\site-packages\PyPDF2\pdf.py", line 482, in write
self._sweepIndirectReferences(externalReferenceMap, self._root)
File "E:\Program_Practice\Python\pachong\venv\lib\site-packages\PyPDF2\pdf.py", line 571, in _sweepIndirectReferences
self._sweepIndirectReferences(externMap, realdata)
File "E:\Program_Practice\Python\pachong\venv\lib\site-packages\PyPDF2\pdf.py", line 547, in _sweepIndirectReferences
value