【发布时间】:2022-12-25 20:19:25
【问题描述】:
在this question之后,我尝试运行以下代码将路径包含汉字的PDF转换为图片:
from pdf2image import convert_from_path
images = convert_from_path('path with Chinese character in it/some Chinese character.pdf', 500)
# save images
我收到此错误消息:
PDFPageCountError: Unable to get page count.
I/O Error: Couldn't open file 'path with Chinese character in it/??????.pdf': No such file or directory.
其中所有汉字都用“?”代替。
这个问题完全是由目录中的中文字符引起的,因为在我确保路径不包含中文字符后程序按预期运行。
在pdf2image.py 中,我试图改变函数pdfinfo_from_path,将out.decode("utf8", "ignore") 更改为例如out.decode("utf32", "ignore"),这也不起作用。
不确定是否相关:根据上述回答,我还需要安装poppler。但是当目录不包含任何汉字时,我的代码也能正常工作。此外,运行此代码conda install -c conda-forge poppler(来自上面的答案)在等待几个小时后永远不会结束。
【问题讨论】: