raceback (most recent call last):
? File "G:\zgxzd\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
try:
return NameObject(name.decode('utf-8'))
except (UnicodeEncodeError, UnicodeDecodeError) as e:
# Name objects should represent irregular characters
# with a '#' followed by the symbol's hex number
try:
return NameObject(name.decode('gbk'))
except (UnicodeEncodeError, UnicodeDecodeError) as e:
if not pdf.strict:
warnings.warn("Illegal character in Name Object", utils.PdfReadWarning)
return NameObject(name)
else:
raise utils.PdfReadError("Illegal character in Name Object")
?又出现如下
? File "G:\zgxzd\venv\lib\site-packages\PyPDF2\utils.py", line 238, in b_ ? ? r = s.encode('latin-1') UnicodeEncodeError: 'latin-1' codec can't encode characters in position 8-9: ordinal not in range(256)
查看代码如下
def b_(s):
bc = B_CACHE
if s in bc:
return bc[s]
if type(s) == bytes:
return s
else:
r = s.encode('latin-1')
if len(s) < 2:
bc[s] = r
return r
修改为
def b_(s):
bc = B_CACHE
if s in bc:
return bc[s]
if type(s) == bytes:
return s
else:
try:
r = s.encode('latin-1')
except Exception as e:
r = s.encode('utf-8')
if len(s) < 2:
bc[s] = r
return r
水印加注成功
?
|