簡體   English   中英

python pdf2image“可能不是 PDF 文件”錯誤

[英]python pdf2image "May not be a PDF file" error

在 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 支持 poppler 支持的所有 PDF 標准。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM