修改后的新代码遇到报错:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/reportlab/lib/utils.py", line 523, in open_for_read
return open_for_read_by_name(name,mode)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/reportlab/lib/utils.py", line 463, in open_for_read_by_name
return open(name,mode)
FileNotFoundError: [Errno 2] No such file or directory: 'SimSun.ttf'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/reportlab/lib/utils.py", line 530, in open_for_read
return BytesIO((datareader if name[:5].lower()=='data:' else rlUrlRead)(name))
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/reportlab/lib/utils.py", line 476, in rlUrlRead
return urlopen(name).read()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 503, in open
req = Request(fullurl, data)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 322, in __init__
self.full_url = url
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 348, in full_url
self._parse()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 377, in _parse
raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: 'SimSun.ttf'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/reportlab/pdfbase/ttfonts.py", line 159, in TTFOpenFile
f = open_for_read(fn,'rb')
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/reportlab/lib/utils.py", line 534, in open_for_read
return open_for_read(name,mode)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/reportlab/lib/utils.py", line 532, in open_for_read
raise IOError('Cannot open resource "%s"' % name)
OSError: Cannot open resource "SimSun.ttf"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/bravesword/Desktop/legal soup/test1.py", line 164, in <module>
save_text_to_pdf(extracted_text, output_pdf)
File "/Users/bravesword/Desktop/legal soup/test1.py", line 117, in save_text_to_pdf
pdfmetrics.registerFont(TTFont('SimSun', 'SimSun.ttf')) # 确保字体文件路径正确
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/reportlab/pdfbase/ttfonts.py", line 1207, in __init__
self.face = TTFontFace(filename, validate=validate, subfontIndex=subfontIndex)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/reportlab/pdfbase/ttfonts.py", line 1088, in __init__
TTFontFile.__init__(self, filename, validate=validate, subfontIndex=subfontIndex)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/reportlab/pdfbase/ttfonts.py", line 447, in __init__
TTFontParser.__init__(self, file, validate=validate,subfontIndex=subfontIndex)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/reportlab/pdfbase/ttfonts.py", line 183, in __init__
self.readFile(file)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/reportlab/pdfbase/ttfonts.py", line 259, in readFile
self.filename, f = TTFOpenFile(f)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/reportlab/pdfbase/ttfonts.py", line 169, in TTFOpenFile
raise TTFError('Can\'t open file "%s"' % fn)
reportlab.pdfbase.ttfonts.TTFError: Can't open file "SimSun.ttf"
最新发布