python-3.xazure-functionsmagickwand

Azure Python function: unable to open image '': No such file or directory @ error/blob.c/OpenBlob/3537


Hello Python Azure Guru's,

I want to creating an Local Azure Python Function which read pdf data from file an convert it to "jpeg" therefor i use imagemagick and the python binder of imagemagick. First i create the python function and which runs succesfully localy without a "Local Azure Python Function". Then i refactor the code to an Local Azure Python Function" run it and receive the following message.

unable to open image 'data/Stephan.pdf': No such file or directory @ error/blob.c/OpenBlob/3537

Below the code of the Python function:

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

Can you please give a solution how to solve this issue! Or are there other methods to do so?


Solution

  • Install pdf2image and poppler,

    Then do this:

    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
        )
    

    This is the structure of my function app:

    enter image description here