0

I'm trying to convert a PowerPoint file to a PDF file using an Azure function which is based on a HTTP trigger. The files are located in one blob storage container as PowerPoints and I want them to be placed in another blob storage container as PDFs whenever the function app is called through a logic app. The idea is that whenever a new file is added to the ppt container, the logic app will call the function app and place the pdf into the pdf container as part of a workflow. The function app can work on one file at a time.

I've been looking at the answers to this question but they require an input path and an output path. I believe this isn't right for my needs as I'll just be passing the blob contents to the function via a logic app. I've developed this so far:

def convert_pptx_to_pdf(inputFile):
    powerpoint = comtypes.client.CreateObject("Powerpoint.Application")
    deck = powerpoint.Presentations.Open(inputFile)

    with tempfile.NamedTemporaryFile(suffix = ".pdf") as temp:
        deck.SaveAs(temp, 32) # causes errors

    output_stream = io.BytesIO()
    deck.output(output_stream, "F")

    return output_stream.getvalue()

def main(req: func.HttpRequest) -> func.HttpResponse:
    pptx_file = req.get_body()

    pdf_data = convert_pptx_to_pdf(pptx_file)

    headers = {
        "Content-Disposition": "attachment;filename=output.pdf",
        "Content-Type": "application/pdf",
    }

    return func.HttpResponse(body=pdf_data, headers=headers, status_code=200)

However, I keep getting this error when I run convert_pptx_to_pdf because the temp file instance is not a string:

ArgumentError: argument 1: : unicode string expected instead of _TemporaryFileWrapper instance

Any suggestions for how to fix this is appreciated or any other suggestions of how to go about doing this are also welcome!

Thanks

1 Answers1

0

The idea is that whenever a new file is added to the ppt container, the logic app will call the function app and place the pdf into the pdf container as part of a workflow. Any suggestions for how to fix this is appreciated or any other suggestions of how to go about doing this are also welcome!

You do not need to call a function app(creating a function app) . Alternatively, you can simply use 3rd party or advanced tools(connectors as actions) in Logic app itself as below:

enter image description here

There are so many connectors through which you can convert into pdf.

After converting you can send the pdf to new container or Storage account by just changing connection In Azure Storage Connector.

RithwikBojja
  • 5,069
  • 2
  • 3
  • 7