问题描述
Python Azure Azure大师,
我想创建一个本地Azure Python函数,该函数从文件中读取pdf数据,然后将其转换为“ jpeg”,为此,我使用了 imagemagick 和imagemagick的python绑定器。首先,我创建python函数,并且在没有“ Local Azure Python Function”的情况下成功地在本地运行。然后,我将代码重构为本地Azure Python函数”,运行它并收到以下消息。
unable to open image 'data/Stephan.pdf': No such file or directory @ error/blob.c/OpenBlob/3537
def convertToJPEG(pdf_url):
try:
print(pdf_url)
pdf = wi(filename= pdf_url,resolution= 300)
print('Read Succesfull')
pdfImage = pdf.convert('jpeg')
print('Converted')
imageBlobs = []
for img in pdfImage.sequence:
imgPage = wi(image=img)
imageBlobs.append(imgPage.make_blob('jpeg'))
return imageBlobs
能否请您提供一个解决此问题的方法!还是有其他方法可以这样做?
解决方法
安装pdf2image和poppler,
然后执行以下操作:
import logging
import azure.functions as func
from pdf2image import convert_from_path
def main(req: func.HttpRequest) -> func.HttpResponse:
path = 'data/Stephan.pdf'
pages = convert_from_path(path,500)
for page in pages:
page.save('data/out.jpg','JPEG')
return func.HttpResponse(
"This HTTP triggered function executed successfully",status_code=200
)
这是我的功能应用程序的结构: