python PyPDF2.utils.PdfReadError: Illegal character in Name Object

在Python 3.7环境中使用PyPDF2模块处理PDF文件时遇到PdfReadError,原因是PDF文件包含多种编码。通过修改PyPDF2源码,包括在generic.py文件中添加处理多编码的代码,以及在utils.py文件中注释和替换特定代码段,可以解决这个问题。
摘要由CSDN通过智能技术生成

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 
  • 13
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值