Docker and serverless | Aspose.Page for Java
Aspose.Page for Java is a cross-platform Java artifact. It does not require a native converter binary in the host image, but containerized deployments must still configure the JVM’s headless and font subsystems correctly.
See Installation to add Aspose.Page for Java to your project.
Docker
Migrating from a native converter
An application that currently calls a native converter may start from an image like this:
1ARG JAVA_RELEASE=21
2FROM eclipse-temurin:${JAVA_RELEASE}-jre-jammy
3
4RUN apt-get update \
5 && apt-get install -y --no-install-recommends \
6 ghostscript \
7 fontconfig \
8 fonts-dejavu-core \
9 && rm -rf /var/lib/apt/lists/*
10
11WORKDIR /app
12COPY target/myapp.jar .
13ENTRYPOINT ["java", "-jar", "myapp.jar"]Dockerfile
With Aspose.Page, no native converter binary is needed in the image. Install fontconfig and the font files required by your documents, and enable headless mode for the JVM:
1ARG JAVA_RELEASE=21
2FROM eclipse-temurin:${JAVA_RELEASE}-jre-jammy
3
4RUN apt-get update \
5 && apt-get install -y --no-install-recommends \
6 fontconfig \
7 fonts-dejavu-core \
8 && rm -rf /var/lib/apt/lists/*
9
10ENV JAVA_TOOL_OPTIONS="-Djava.awt.headless=true"
11
12WORKDIR /app
13COPY target/myapp.jar .
14ENTRYPOINT ["java", "-jar", "myapp.jar"]Both files default to Java 21. Override JAVA_RELEASE as a build argument when your application targets a different Java release.
Two Java-specific things that will bite you
Headless mode
Aspose.Page uses java.awt types while parsing PostScript, not only when rasterizing content. Headless mode is therefore required for every operation, including a plain PS-to-PDF conversion that produces no image.
In a container, AWT may try to connect to a display unless headless mode is enabled:
1-Djava.awt.headless=trueSet this as a JVM flag or through JAVA_TOOL_OPTIONS, not in application code. AWT may already have initialized before main runs.
Headless mode is not limited to image output. Keep it enabled for all Aspose.Page operations in containers and serverless runtimes because PostScript parsing itself uses AWT.
fontconfig, and fonts only if you need them
fontconfig and font files are separate requirements:
fontconfigis always required. Aspose.Page instantiatesjava.awt.Fontregardless of document content, so the JVM font subsystem must initialize even when every font is embedded in the input.- Font files are required only when documents reference system fonts by name. If a named font is unavailable, a substitute can be used and conversion can still succeed, but the output typography may differ from the source.
Aspose.Page embeds Liberation Serif as a fallback. This helps conversion continue when a font is missing, but it also means that missing fonts may appear as changed typography instead of a conversion failure.
If all input documents embed their fonts, an image with fontconfig and no additional font packages can be sufficient. For arbitrary third-party documents, install a practical font set:
1RUN apt-get install -y --no-install-recommends fonts-dejavu-core fonts-liberationLiberation Sans and Liberation Mono are metric-compatible substitutes for Arial and Courier New. To use font files shipped with your application, configure PdfSaveOptions:
1PdfSaveOptions options = new PdfSaveOptions(true);
2options.setAdditionalFontsFolders(new String[] { "/app/fonts" });The operating system’s standard font folders are searched in addition to the folders you specify.
To determine what your documents need, convert representative files in an image that has fontconfig but no font packages, inspect the diagnostics, and compare the output with a known-good render. A successful conversion and a non-empty output file do not prove that the intended fonts were used.
Diagnose font substitutions and conversion errors
Load the input with
PsDocument and use PdfSaveOptions(true) to make the supressErrors setting explicit. Recoverable conversion errors are collected in getExceptions():
1PsDocument document = new PsDocument("input.ps");
2PdfSaveOptions options = new PdfSaveOptions(true);
3
4document.saveAsPdf("output.pdf", options);
5
6for (Exception ex : options.getExceptions()) {
7 System.out.println("Conversion notice: " + ex.getMessage());
8}The API spells setSupressErrors(boolean) and isSupressErrors() with one p. Do not skip the exception loop in an unattended pipeline; record every recoverable conversion problem.
During local diagnosis, enable debug output:
1options.setDebug(true);Debug messages are written to standard output and are useful during deployment validation. The API reference does not identify a dedicated font-substitution event, so enable both error collection and debug output while testing a document that references an unavailable font. Preserve the channel that reports the condition in your deployment, and visually compare the resulting PDF with a known-good render.
Alpine and distroless images
Alpine images need fontconfig and, when documents reference system fonts, an appropriate package such as ttf-dejavu. Distroless images have no package manager, so copy the font configuration and any required font files from a build stage. Validate the JVM font subsystem and representative documents in the exact runtime image you deploy.
AWS Lambda
Aspose.Page is deployed with the Java application, so the function does not require a native converter layer. The following handler assumes that application-specific methods download the input to Lambda’s writable /tmp directory and upload the result. It creates an
Aspose.Page License once when the class is initialized:
1import com.aspose.eps.PsDocument;
2import com.aspose.eps.device.PdfSaveOptions;
3import com.aspose.page.License;
4
5public class ConvertHandler implements RequestHandler<S3Event, String> {
6
7 static {
8 try {
9 new License().setLicense("Aspose.Page.Java.lic");
10 } catch (Exception e) {
11 throw new RuntimeException("License failed", e);
12 }
13 }
14
15 @Override
16 public String handleRequest(S3Event event, Context context) {
17 String inputPath = "/tmp/input.ps";
18 String outputPath = "/tmp/output.pdf";
19
20 downloadFromS3(event, inputPath);
21
22 PsDocument document = new PsDocument(inputPath);
23 PdfSaveOptions options = new PdfSaveOptions(true);
24 options.setAdditionalFontsFolders(new String[] { "/var/task/fonts" });
25
26 document.saveAsPdf(outputPath, options);
27
28 for (Exception ex : options.getExceptions()) {
29 context.getLogger().log("Conversion notice: " + ex.getMessage());
30 }
31
32 uploadToS3(outputPath);
33 return "ok";
34 }
35}Set JAVA_TOOL_OPTIONS=-Djava.awt.headless=true as a Lambda environment variable. Ship required fonts in the deployment package under /var/task and reference them explicitly, or use a container image whose font packages you control. Lambda assigns CPU in proportion to memory, so test memory settings with representative documents. Applying the license in a static block avoids repeating that work for every invocation handled by the same execution environment.
Kubernetes and Spring Boot
The application JAR carries Aspose.Page, so the container can use the same probes and resource limits as the rest of the service. Set headless mode and choose a memory limit based on representative documents:
1env:
2 - name: JAVA_TOOL_OPTIONS
3 value: "-Djava.awt.headless=true"
4resources:
5 limits:
6 memory: "1Gi"Conversion is CPU-bound, and memory use scales with page complexity. Put conversion behind a bounded executor or a queue instead of allowing large documents to compete without limit with HTTP request handling.
Licensing
Review the deployment and distribution terms in Licensing.
Checklist for containerized conversion
- Set
-Djava.awt.headless=trueas a JVM flag or throughJAVA_TOOL_OPTIONS, not in code. - Install
fontconfigunconditionally, including for documents with embedded fonts. - Determine whether input documents embed fonts or reference them by name, and install font files when required.
- Enable
supressErrorsand log every entry returned byoptions.getExceptions(). - Test missing-font behavior with debug output enabled and preserve the diagnostic channel used by the deployed library.
- Use a writable temporary path such as
/tmpon Lambda. - Apply the license once at startup or class initialization, not once per request.
- Test the memory limit with the largest representative document.
- Visually compare output with a known-good render instead of checking only for a non-empty file.
Font substitution can produce a valid PDF whose typography differs from the source, so visual validation is an essential deployment check.