python pdf2image "May not be a PDF file"错误

标签 python centos pdf2image

在 Centos 8 操作系统上,使用 Python 将 pdf 页面转换为 jpg 文件时出现错误。

from pdf2image import convert_from_path
import sys

images = convert_from_path("test.pdf",500)
for i in range(len(images)):
    images[i].save('page'+ str(i) +'.jpg', 'JPEG')

结果,它给出了这个错误。我可以在本地运行 PDF 文件,但是当我想将它保存为 jpg 时它不起作用。
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/pdf2image/pdf2image.py", line 479, in pdfinfo_from_path
    raise ValueError
ValueError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pdf_conv.py", line 7, in <module>
    images = convert_from_path(pdf_path,500)
  File "/usr/local/lib/python3.6/site-packages/pdf2image/pdf2image.py", line 98, in convert_from_path
    page_count = pdfinfo_from_path(pdf_path, userpw, poppler_path=poppler_path)["Pages"]
  File "/usr/local/lib/python3.6/site-packages/pdf2image/pdf2image.py", line 489, in pdfinfo_from_path
    "Unable to get page count.\n%s" % err.decode("utf8", "ignore")
pdf2image.exceptions.PDFPageCountError: Unable to get page count.
Syntax Warning: May not be a PDF file (continuing anyway)
Syntax Error: Couldn't find trailer dictionary
Syntax Error: Couldn't find trailer dictionary
Syntax Error: Couldn't read xref table

最佳答案

PDF != PDF - 它有不同的版本。愿你的 python pdf2image不喜欢/不知道您提供的 PDF 类型。使用 AcrobatReader 或类似工具检查您要转换的内容,看看是否 pdf2image支持它。
Which ISO standards does pdf2image support (简称:pdf2image supports all PDF standards that poppler supports.)

关于python pdf2image "May not be a PDF file"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71814599/

相关文章:

node.js - 在 Node.js 和 CentOS 中使用 pdf2image

python - argmin 方法的返回类型

python - PCA 分解的 k 均值簇的质心是多少?

python - 为什么 django 给出错误 : no module named django. 核心?

elasticsearch - 如何让 Elasticsearch 在 Centos 6.5 中运行?

docker -/bin/sh : service: command not found on cent os 7

php - Plesk (Linux) 的自定义 .htaccess 404 页面

python - 将 PDF 转换为图像的省时方法

python - 如何在 python 脚本中从 Github API 检索数据?