Is It Possible to Use Aspose.Slides in an Azure Function App without a Container?

Hi All,

we are trying to use aspose.words (25.7.0) and aspose.slides (25.7.0) in a “plain” Azure Function App (Python 3.12) but as soon as we add the import for these packages the functions do not load anymore. We were able to use them by containerizing the function app project and installing libgdiplus within the dockerfile but we would prefer to use the packages without containers. But since libgdiplus cant be installed on plain Azure Functions host I dont think there is any chance to use it like we intended to do.

Is there any way to use these packages in a “plain” Azure Function App (Python 3.12) without using a container?

Any advice or best practices would be greatly appreciated.

Python packages in question:
Aspose.Words for Python
Aspose.Slides for Python via .NET

Example Dockerfile we used to confirm containerized function app project works:

FROM mcr.microsoft.com/azure-functions/python:4-python3.12

RUN apt-get update &&
apt-get install -y libgdiplus &&
apt-get clean

Example Function we used to confirm containerized function app project works:

import logging
import io
import os
import azure.functions as func

def main(req: func.HttpRequest) → func.HttpResponse:
“”"
HTTP POST: Accept PPTX bytes in the request body and return PDF.

- Content-Type: application/octet-stream
- Query param: filename=yourdeck.pptx (optional)
"""
try:
    # If GET, provide a simple help message (do not require Aspose import)
    if req.method.upper() == "GET":
        return func.HttpResponse(
            body=b"Aspose endpoint is ready. POST PPTX bytes to receive PDF.",
            status_code=200,
            mimetype="text/plain",
        )

    # Validate dependency only for POST
    try:
        **import aspose.slides as slides**
    except ImportError:
        logging.error("Aspose.Slides not installed. Add 'aspose.slides' to requirements.txt")
        return func.HttpResponse(
            body=b'{"error":"Aspose.Slides not installed. Install with pip: aspose.slides"}',
            status_code=500,
            mimetype="application/json",
        )

    # Read input (POST)
    pptx_bytes = req.get_body() or b""
    if not pptx_bytes:
        logging.warning("No PPTX content provided in request body")
        return func.HttpResponse(
            body=b'{"error":"No PPTX content provided"}',
            status_code=400,
            mimetype="application/json",
        )

    filename = req.params.get("filename", "uploaded.pptx")

    # Convert PPTX -> PDF
    pptx_stream = io.BytesIO(pptx_bytes)
    presentation = slides.Presentation(pptx_stream)

    pdf_stream = io.BytesIO()
    presentation.save(pdf_stream, slides.export.SaveFormat.PDF)
    pdf_bytes = pdf_stream.getvalue()

    logging.info("Conversion succeeded: %s -> PDF (%d bytes)", filename, len(pdf_bytes))
    return func.HttpResponse(
        body=pdf_bytes,
        status_code=200,
        mimetype="application/pdf",
        headers={
            "Content-Disposition": f"inline; filename={os.path.splitext(filename)[0]}.pdf",
        },
    )
except Exception as e:
    # Top-level catch-all to ensure 500 includes error details and a log entry
    logging.exception("Unhandled error in Aspose conversion")
    return func.HttpResponse(
        body=("{\"error\": \"%s\"}" % str(e)).encode("utf-8"),
        status_code=500,
        mimetype="application/json",
    )

@alrabu

What you are trying to do

You are importing aspose.words and aspose.slides in a plain Azure Functions (Linux) host that runs Python 3.12. As soon as the import statement is executed the function app fails to start. In a custom Docker image you solved the problem by installing libgdiplus (the Linux implementation of GDI+) — the same library that the Aspose .NET‑based Python packages need for rendering and PDF conversion [1].

Why it does not work on the “plain” Azure Functions host

  • Aspose.Slides for Python via .NET (and Aspose.Words for Python via .NET when you use PDF/graphics features) are thin wrappers around the native .NET libraries. On Linux they depend on libgdiplus for any GDI+‑based operation (e.g., rendering slides, converting to PDF, measuring text, etc.).
  • The standard Azure Functions Linux sandbox does not allow you to install additional native packages such as libgdiplus. Consequently the native dependency cannot be satisfied and the runtime aborts during module import.

Result: The packages cannot be used on a plain (non‑containerized) Linux Azure Functions app.

What you can do instead

Option How it works When to use it
1. Keep using a custom container (the approach that already works) Build a Docker image based on mcr.microsoft.com/azure-functions/python and install libgdiplus (or any other native libs you need). Deploy the function app as a Linux container (Consumption, Premium, or Dedicated). Preferred if you need the full on‑premise Aspose API (e.g., high‑performance batch conversion) and you are comfortable maintaining a container image.
2. Switch to a Windows‑based Function App Deploy the function app to an App Service plan (or Premium plan) that runs on Windows. Windows already provides the GDI+ implementation, so no extra native package is required. Viable if you can run your function on Windows and do not need the Linux‑only features of the consumption plan.
3. Use Aspose Cloud REST APIs Call the Aspose.Slides Cloud (or Aspose.Words Cloud) services via HTTP. The cloud service performs all rendering/conversion on Aspose’s servers, so no native dependencies are required on your function host. Ideal for a truly “server‑less” scenario where you want to avoid any native libraries, keep the function lightweight, or run on the standard Linux consumption plan.
4. Alternative Azure services If you need a managed environment that allows native libs, consider Azure Container Apps or Azure Kubernetes Service (AKS) where you can run the same Docker image without the Functions sandbox restrictions. Useful when you want a fully managed platform but still need custom native dependencies.

Best‑practice recommendation

  • For production workloads that rely heavily on Aspose rendering (PDF, PPTX → PDF, image export, etc.), the container‑based deployment you already have is the most reliable and performant choice.
  • If you prefer a server‑less model without managing containers, switch to the Aspose Cloud APIs; they expose the same functionality via REST and are fully supported on any Azure Functions plan.
  • If you must stay on the Azure Functions platform and cannot use containers, the only viable path is to move the function to a Windows App Service plan, where GDI+ is available out‑of‑the‑box.

Next steps for you

  1. Choose the deployment model that fits your constraints (container, Windows plan, or Cloud API).

  2. If you stay with containers, keep the Dockerfile you already verified:

    FROM mcr.microsoft.com/azure-functions/python:4-python3.11
    RUN apt-get update && \
        apt-get install -y libgdiplus && \
        apt-get clean
    
  3. If you decide to use the Cloud APIs, replace the local import/processing with calls to the Aspose.Slides Cloud endpoint (see the Aspose.Slides Cloud documentation for authentication and request format).

  4. If you move to a Windows Function App, simply remove the libgdiplus installation step; the same Python code will load the Aspose assemblies without error.

Feel free to share any additional constraints (e.g., cost, latency, licensing) and we can help you fine‑tune the chosen approach.

@alrabu,
Thank you for posting the question.

We have opened the following new ticket(s) in our internal issue tracking system and will answer your question according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESPYNET-323