运行pdf2image python脚本时出错

时间:2019-11-25 19:36:54

标签: python-3.x vb.net error-handling

所以我以前曾经有过此脚本,并且我一直在尝试通过使其成为EXE使其在VB.NET应用程序中工作。当我尝试将其作为脚本或EXE运行时,出现此错误

回溯(最近通话最近一次):

File "C:\Python\PDF Convertor\venv\lib\site-packages\pdf2image\pdf2image.py", line 365, in _page_count
    return int(re.search(r"Pages:\s+(\d+)", out.decode("utf8", "ignore")).group(1))
AttributeError: 'NoneType' object has no attribute 'group'

在处理上述异常期间,发生了另一个异常:

回溯(最近通话最近一次):

  File "C:/Python/PDF Convertor/PDF2JPEG.py", line 18, in <module>
    pages = convert_from_path(fileLocation, 500)
  File "C:\Python\PDF Convertor\venv\lib\site-packages\pdf2image\pdf2image.py", line 82, in convert_from_path
    page_count = _page_count(pdf_path, userpw, poppler_path=poppler_path)
  File "C:\Python\PDF Convertor\venv\lib\site-packages\pdf2image\pdf2image.py", line 368, in _page_count
    "Unable to get page count. %s" % err.decode("utf8", "ignore")
pdf2image.exceptions.PDFPageCountError: Unable to get page count. I/O Error: Couldn't open file 'C:\Python\PDF2JPEG\Employee Directory (Revised 5.21.19)-converted - Copy (2).pdf': No such file or directory.

我正在运行的代码如下:

from pdf2image import convert_from_path
import time

pdfLocation = open("PDFLocation.txt", "r", encoding="utf8" )
fileLocation = pdfLocation.read()
print(fileLocation)
pdfLocation.close()
saveLocation = open("SaveLocation.txt", "r",encoding="utf8")
locationSave = saveLocation.read()
print(locationSave)
saveLocation.close()

pages = convert_from_path(fileLocation, 500)
for page in pages:
    page.save(f'{locationSave}\ConvertedImage1.jpg', 'JPEG')

print("Conversion Complete")
time.sleep(5)

为什么会出现此错误?

0 个答案:

没有答案