我在convert_from_bytes pdf2image python3上得到BrokenPipeError

时间:2018-04-06 18:10:53

标签: python-3.x pypdf2

请帮忙,这个脚本在OSX上运行得很好,但是不能在windows10上运行。 (但是我需要)...这个程序会将conver页面提取为.png,但它会给出BrokenPipeError

from pdf2image import convert_from_bytes
from PyPDF2 import PdfFileWriter, PdfFileReader
import io
import sys
import os

def get_cover(input_file, ext):
    inp = PdfFileReader(input_file+ext, "rb")
    page = inp.getPage(0)

    wrt = PdfFileWriter()
    wrt.addPage(page)

    r = io.BytesIO()
    wrt.write(r)

    images = convert_from_bytes(r.getvalue())
    images[0].save(input_file+".png")
    print("Done, your cover photo has been saved as {}.".format(input_file+".png"))
    r.close()

if len(sys.argv)>1:
    input_file = sys.argv[1]
    get_cover(*os.path.splitext(input_file))
else:
    for f in os.listdir():
        f = os.path.splitext(f)
        if f[1]==".pdf":
            print("Processing {}{}".format(*f))
            get_cover(*f)

错误消息:

PdfReadWarning: Xref table not zero-indexed. ID numbers for objects will be corrected. [pdf.py:1736]
Traceback (most recent call last):
  File "PDF_cover_extractor.py", line 30, in <module>
    get_cover(*f)
  File "PDF_cover_extractor.py", line 17, in get_cover
    images = convert_from_bytes(r.getvalue())
  File "C:\Program Files\Python35\lib\site-packages\pdf2image\pdf2image.py", line 55, in convert_from_bytes
    proc.stdin.write(pdf_file)
BrokenPipeError: [Errno 32] Broken pipe

0 个答案:

没有答案