Docker and serverless | Aspose.Page for .NET

Start here: use the right package

Choose the package that matches the operating system on which your application runs.

PackageGraphics backendLinux containers
Aspose.PageSystem.Drawing.CommonNo — Windows only on .NET 7 and later
Aspose.Page.DrawingAspose.Drawing (managed)Yes

System.Drawing.Common is supported only on Windows starting with .NET 7. Because the main Aspose.Page package depends on it, use Aspose.Page.Drawing in Linux containers and serverless Linux environments. Aspose.Page.Drawing provides the same API with a managed graphics backend and targets .NET Standard 2.0 and .NET 7.0, which also covers .NET 8 and later.

See Installation for the package setup used on each platform.

1dotnet add package Aspose.Page.Drawing

Your using statements and conversion code remain unchanged. Install only one of the two packages.

Docker

Migrating from a native converter

The following starting image installs a native converter and its font package:

 1FROM mcr.microsoft.com/dotnet/aspnet:8.0-bookworm-slim
 2
 3RUN apt-get update \
 4 && apt-get install -y --no-install-recommends \
 5      ghostscript \
 6      fonts-dejavu-core \
 7 && rm -rf /var/lib/apt/lists/*
 8
 9WORKDIR /app
10COPY --from=build /app/publish .
11ENTRYPOINT ["dotnet", "MyApp.dll"]

When the application uses Aspose.Page.Drawing, the native converter binary is not required in the image.

Dockerfile

Install fontconfig and the font files required by your documents:

 1FROM mcr.microsoft.com/dotnet/aspnet:8.0-bookworm-slim
 2
 3RUN apt-get update \
 4 && apt-get install -y --no-install-recommends \
 5      fontconfig \
 6      fonts-dejavu-core \
 7 && rm -rf /var/lib/apt/lists/*
 8
 9WORKDIR /app
10COPY --from=build /app/publish .
11ENTRYPOINT ["dotnet", "MyApp.dll"]

Configure fonts

A working font configuration is always required. The managed Aspose.Drawing backend initializes font handling regardless of what is inside the document, so install fontconfig even when every font is embedded in the input file.

Font files are required only when a document references system fonts by name:

Aspose.Page embeds Liberation Serif as a fallback. Consequently, a missing font normally changes the rendered typography instead of causing a missing-font exception. For arbitrary third-party documents, install a practical set of fonts:

1RUN apt-get install -y --no-install-recommends fonts-dejavu-core fonts-liberation

Liberation Sans and Liberation Mono are metric-compatible substitutes for Arial and Courier New. If you supply specific font files with the application, configure PdfSaveOptions through AdditionalFontsFolders:

1var options = new PdfSaveOptions(true)
2{
3    AdditionalFontsFolders = new[] { "/app/fonts" }
4};

The operating system’s standard font folders are searched in addition to the folders you specify.

Diagnose font substitutions and conversion errors

Load the input with PsDocument and call SaveAsPdf with PdfSaveOptions to collect recoverable conversion errors. The API spells SupressErrors with one p. When it is true, suppressed conversion errors are available through Exceptions:

1var document = new PsDocument("input.ps");
2var options = new PdfSaveOptions(true);
3
4document.SaveAsPdf("output.pdf", options);
5
6foreach (Exception ex in options.Exceptions)
7{
8    Console.WriteLine($"Conversion notice: {ex.Message}");
9}

During local diagnosis, enable Debug to write conversion diagnostics to standard output:

1options.Debug = true;

The API reference documents the error collection and debug channels but does not identify a dedicated font-substitution event. When validating a deployment, enable both channels, convert a file that references an unavailable font, record the diagnostics produced by your library version, and compare the PDF with a known-good render. Do not use a successful conversion or a non-empty output file as proof that the intended fonts were used.

Compare container images

Save the two Dockerfiles shown above as Dockerfile.native and Dockerfile.managed, then build both with your own application and base image:

1docker build -t myapp:native  -f Dockerfile.native .
2docker build -t myapp:managed -f Dockerfile.managed .
3docker images | grep myapp

To inspect the packages installed in each Debian-based image:

1docker run --rm myapp:native  dpkg -l | wc -l
2docker run --rm myapp:managed dpkg -l | wc -l

AWS Lambda

Aspose.Page.Drawing is deployed as part of the .NET Lambda package, so the function does not require a native converter layer. The following conversion method assumes that the handler has downloaded its input to Lambda’s writable /tmp directory. It creates an Aspose.Page license and calls SetLicense once when the function class is initialized, then converts with file paths:

 1using System;
 2using Amazon.Lambda.Core;
 3using Aspose.Page.EPS;
 4using Aspose.Page.EPS.Device;
 5
 6public class Function
 7{
 8    static Function()
 9    {
10        var license = new Aspose.Page.License();
11        license.SetLicense("Aspose.Page.NET.lic");
12    }
13
14    private static string ConvertDocument(string inputPath, ILambdaLogger logger)
15    {
16        var outputPath = "/tmp/output.pdf";
17        var document = new PsDocument(inputPath);
18
19        // Suppress minor errors and collect them instead.
20        var options = new PdfSaveOptions(true);
21        document.SaveAsPdf(outputPath, options);
22
23        foreach (Exception ex in options.Exceptions)
24        {
25            logger.LogWarning(ex.Message);
26        }
27
28        return outputPath;
29    }
30}

Ship any required font files in the deployment package and set AdditionalFontsFolders to their extracted path, or use a container image in which you control the font packages. Conversion is CPU-bound and memory use depends on page complexity. Because Lambda assigns CPU in proportion to memory, test several memory settings with representative documents.

Azure Functions

Native packages cannot be installed on the Azure Functions Consumption plan: there is no elevated package-installation step or persistent host to prepare. A managed NuGet package is deployed with the function and does not require a native converter installation.

The .NET API supports both the stream constructor for PsDocument and the stream overload of SaveAsPdf, so an HTTP-triggered function can convert the request body without an intermediate file:

 1using System;
 2using System.IO;
 3using System.Net;
 4using System.Threading.Tasks;
 5using Aspose.Page.EPS;
 6using Aspose.Page.EPS.Device;
 7using Microsoft.Azure.Functions.Worker;
 8using Microsoft.Azure.Functions.Worker.Http;
 9using Microsoft.Extensions.Logging;
10
11public class ConvertFunction
12{
13    private readonly ILogger<ConvertFunction> _logger;
14
15    public ConvertFunction(ILogger<ConvertFunction> logger) => _logger = logger;
16
17    [Function("ConvertPostScript")]
18    public async Task<HttpResponseData> Run(
19        [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req)
20    {
21        using var input = new MemoryStream();
22        await req.Body.CopyToAsync(input);
23        input.Position = 0;
24
25        var document = new PsDocument(input);
26
27        // Suppress minor errors and collect them instead.
28        var options = new PdfSaveOptions(true);
29
30        using var output = new MemoryStream();
31        document.SaveAsPdf(output, options);
32
33        foreach (Exception ex in options.Exceptions)
34        {
35            _logger.LogWarning("Conversion notice: {Message}", ex.Message);
36        }
37
38        var response = req.CreateResponse(HttpStatusCode.OK);
39        response.Headers.Add("Content-Type", "application/pdf");
40        output.Position = 0;
41        await output.CopyToAsync(response.Body);
42        return response;
43    }
44}

On the Consumption plan, ship required font files with the function and point AdditionalFontsFolders to them because operating-system font packages cannot be installed.

Licensing

Review the deployment and distribution terms in Licensing and Subscription.

Checklist for containerized conversion

Font substitution can produce a valid PDF with typography that differs from the source, so visual validation is an essential deployment check.