How to Run IronPDF for Java in Google Cloud
Deploying IronPDF for Java on Google Cloud Functions requires a non-default configuration because IronPDF relies on a bundled Chromium binary to render HTML into PDF. This guide covers everything needed to run IronPDF inside a custom Docker container on Google Cloud Functions — from the correct pom.xml dependencies to runtime permissions and resource settings.
This is not a concern if you are already comfortable with Google Cloud Functions and Docker. The configuration changes are straightforward: swap the default function image for a custom Dockerfile, add the Linux engine dependency, tune the resource limits, and set the working directory. Each step is explained below.
Quickstart: Deploy IronPDF for Java on Google Cloud
The minimal working configuration requires a custom Dockerfile (because the default Cloud Function images lack Chrome's system dependencies), the ironpdf-engine-linux-x64 artifact in your pom.xml, and a working directory pointing to /tmp/. The code below shows how to set the engine working directory in your function entry point:
//:path=/static-assets/pdf/content-code-examples/tutorials/google-cloud/configure-working-directory.java
import com.ironsoftware.ironpdf.Settings;
import java.nio.file.Paths;
// Point IronPDF at a writable directory in the Cloud Function runtime
Settings.setIronPdfEngineWorkingDirectory(Paths.get("/tmp/"));
//:path=/static-assets/pdf/content-code-examples/tutorials/google-cloud/configure-working-directory.java
import com.ironsoftware.ironpdf.Settings;
import java.nio.file.Paths;
// Point IronPDF at a writable directory in the Cloud Function runtime
Settings.setIronPdfEngineWorkingDirectory(Paths.get("/tmp/"));
After setting the working directory, IronPDF can extract and execute its engine binary within the Cloud Function's ephemeral filesystem. The /tmp/ directory is the only writable, executable path available in most Google Cloud Function runtimes.
Table of Contents
- Why Don't Default Cloud Function Images Work?
- How Do I Build a Custom Dockerfile for Google Cloud?
- How Do I Configure pom.xml for Google Cloud Deployment?
- How Do I Add the Maven Shade Plugin?
- How Do I Add Optional gRPC Dependencies?
- How Do I Set Resource Limits for Google Cloud Functions?
- How Do I Configure the Working Directory and File Permissions?
- What Are the Next Steps?
Why Don't Default Cloud Function Images Work?
Default Google Cloud Function runtime images are minimal by design — they include only the packages needed to execute function code written in common languages. IronPDF's Chromium-based rendering engine depends on a broader set of Linux system libraries (fonts, graphics libraries, sandboxing tools) that are absent from the standard images.
Google publishes a full list of available system packages for each runtime at the Google Cloud Functions system packages reference. Chromium's dependencies are not included in any of the standard 2nd-gen runtimes. Attempting to load the IronPDF engine in the default image results in a native library load failure at startup.
The solution is to build a custom Docker image that explicitly installs those packages before the function binary is added. This approach is fully supported by Google Cloud Functions and is the same strategy recommended for any function that requires native binaries. Refer to the IronPDF Linux deployment guide for the complete list of packages to include.
How Do I Build a Custom Dockerfile for Google Cloud?
A custom Dockerfile gives complete control over the runtime environment. Start from the official Google Cloud Functions Java base image, then install the system libraries that Chromium requires.
The Dockerfile below demonstrates the recommended pattern. Replace the COPY and CMD entries with the specifics of your function project:
//:path=Dockerfile
# Use the official Google Cloud Functions Java 17 base image
FROM gcr.io/google-appengine/java17:latest
# Install Chrome system dependencies required by IronPDF's rendering engine
RUN apt-get update && apt-get install -y \
libglib2.0-0 \
libnss3 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libdrm2 \
libxkbcommon0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxrandr2 \
libgbm1 \
libasound2 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
# Grant execute permissions on /tmp so the IronPDF engine can extract there
RUN chmod 777 /tmp/
# Copy the compiled JAR and set the entry point
COPY target/your-function.jar /app/function.jar
CMD ["java", "-jar", "/app/function.jar"]
The chmod 777 /tmp/ line is necessary because IronPDF needs to write and execute the engine binary during initialization. Without execute permission on the working directory, the engine will fail to start.
docker build and docker run before deploying to Cloud Functions. Local testing catches missing dependencies early and avoids slow cloud build cycles.How Do I Configure pom.xml for Google Cloud Deployment?
The standard ironpdf Maven artifact bundles engine binaries for multiple platforms. For Google Cloud Functions (which run on Linux x86-64), add the platform-specific engine artifact to keep the deployment image lean and to ensure the correct binary is always available:
//:path=pom.xml
<dependencies>
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf</artifactId>
<version>2024.9.1</version>
</dependency>
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf-engine-linux-x64</artifactId>
<version>2024.9.1</version>
</dependency>
</dependencies>
//:path=pom.xml
<dependencies>
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf</artifactId>
<version>2024.9.1</version>
</dependency>
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf-engine-linux-x64</artifactId>
<version>2024.9.1</version>
</dependency>
</dependencies>
Always update the version number to the latest IronPDF for Java release. The ironpdf-engine-linux-x64 artifact must match the version of the core ironpdf artifact exactly.
How Do I Add the Maven Shade Plugin?
When deploying to Google Cloud Functions as an uber-JAR (fat JAR), the maven-shade-plugin ensures that service loader files from all transitive dependencies are merged correctly. Without it, some gRPC service registrations can be silently dropped, causing the engine to fail to initialize.
Add the following plugin configuration to the <build><plugins> section of your pom.xml:
//:path=pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
//:path=pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
The ServicesResourceTransformer is the critical piece. It combines META-INF/services/ entries from every dependency JAR into a single merged file. gRPC uses Java's ServiceLoader mechanism, so merged service files are required for transport selection (HTTP/2 vs. plain text) to work at runtime.
How Do I Add Optional gRPC Dependencies?
In some deployment configurations — particularly when using a shaded JAR with certain versions of the Google Cloud Functions framework — explicit gRPC transport dependencies are needed. Add these if the function fails to start with a gRPC transport or channel error:
//:path=pom.xml
<dependencies>
<dependency>
<groupId>io.perfmark</groupId>
<artifactId>perfmark-api</artifactId>
<version>0.26.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-okhttp</artifactId>
<version>1.50.2</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>1.50.2</version>
</dependency>
</dependencies>
//:path=pom.xml
<dependencies>
<dependency>
<groupId>io.perfmark</groupId>
<artifactId>perfmark-api</artifactId>
<version>0.26.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-okhttp</artifactId>
<version>1.50.2</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>1.50.2</version>
</dependency>
</dependencies>
In most cases, including grpc-netty-shaded is sufficient for production. The grpc-okhttp transport is a lighter alternative useful when minimizing image size is a priority. Add perfmark-api only if you encounter classpath warnings about missing tracing annotations.
How Do I Set Resource Limits for Google Cloud Functions?
IronPDF starts a Chromium subprocess inside the Cloud Function container during its first invocation. Chromium's startup and initial rendering are memory-intensive, and the function must remain alive long enough for the engine to initialize. The default resource limits for Cloud Functions are too low for reliable operation.
Configure the following limits in the Google Cloud Console or via the gcloud CLI when deploying the function:
| Setting | Recommended Value | Reason |
|---|---|---|
| Timeout | 330 seconds | Chromium initialization on a cold start can take 60–90 seconds. The function must not time out before the engine is ready. |
| Memory | 2,048 MB or higher | Chromium requires significant RAM to render complex HTML pages. Insufficient memory causes the process to be killed mid-render. |
| Ephemeral Storage | 1,024 MB or higher | The engine binary and temporary PDF files are written to /tmp/. Low storage causes extraction or write failures. |
These values are starting points. High-volume or complex PDF generation may require higher memory allocations. Monitor Cloud Function memory usage metrics in the Google Cloud Console and increase limits if you observe out-of-memory errors.
How Do I Configure the Working Directory and File Permissions?
The IronPDF engine extracts its binary to a working directory at startup. On Google Cloud Functions, the only writable and executable path is /tmp/. Set the working directory explicitly before calling any IronPDF API, and ensure the Dockerfile grants the necessary permissions on that path.
Add this configuration call at the top of your function entry point, before any PDF operations:
//:path=/static-assets/pdf/content-code-examples/tutorials/google-cloud/configure-working-directory.java
import com.ironsoftware.ironpdf.Settings;
import java.nio.file.Paths;
public class PdfFunction {
static {
// Must be called before any IronPDF operation.
// /tmp/ is the only writable and executable directory in Cloud Functions.
Settings.setIronPdfEngineWorkingDirectory(Paths.get("/tmp/"));
}
}
//:path=/static-assets/pdf/content-code-examples/tutorials/google-cloud/configure-working-directory.java
import com.ironsoftware.ironpdf.Settings;
import java.nio.file.Paths;
public class PdfFunction {
static {
// Must be called before any IronPDF operation.
// /tmp/ is the only writable and executable directory in Cloud Functions.
Settings.setIronPdfEngineWorkingDirectory(Paths.get("/tmp/"));
}
}
Then add the corresponding permission command to your Dockerfile:
//:path=Dockerfile
# Ensure the IronPDF engine can extract and run binaries from /tmp/
RUN chmod 777 /tmp/
Using a static {} initializer block guarantees the working directory is configured before any class in your function attempts to load the IronPDF engine. If you set it in an instance method or request handler, there is a risk that another thread initializes the engine before the path is configured.
What Are the Next Steps?
This guide covers the complete configuration for running IronPDF for Java inside a Google Cloud Function using a custom Docker container. The key points are: use a custom Dockerfile that installs Chrome system dependencies, include the ironpdf-engine-linux-x64 Maven artifact, configure the working directory to /tmp/, set the timeout to at least 330 seconds and memory to at least 2,048 MB, and add the maven-shade-plugin to merge service loader files.
To explore more of what IronPDF for Java can do, visit the IronPDF for Java documentation or try one of these guides:
- IronPDF for Java on Linux — Understand the full list of Chrome dependencies for Linux deployments
- IronPDF for Java on AWS Lambda — Similar Docker-based deployment guide for AWS
- HTML to PDF conversion in Java — Core rendering workflow for your function logic
Get a free trial license to test IronPDF for Java in your Google Cloud environment. A license key is required for production deployments. Purchase a license when you are ready to go live.
Frequently Asked Questions
Why does IronPDF for Java fail to start on the default Google Cloud Function image?
Default Cloud Function runtime images do not include the Linux system libraries that Chromium requires, such as libnss3, libatk1.0-0, and related graphics packages. IronPDF's rendering engine uses Chromium internally, so a custom Dockerfile that explicitly installs these dependencies is required.
Why is Zip Deployment not supported for IronPDF on Google Cloud?
IronPDF must extract and execute a native Chromium binary at runtime. The Zip Deployment model does not provide a writable, executable filesystem, so the engine cannot extract or launch its binary. A Docker-based deployment is required.
What Maven dependency is required for IronPDF on Google Cloud Functions?
Add ironpdf-engine-linux-x64 from the com.ironsoftware group to your pom.xml. The version number must match the core ironpdf artifact exactly. This artifact bundles the Linux x86-64 Chromium binary used by IronPDF for rendering.
Why does IronPDF for Java need the maven-shade-plugin?
When packaging as an uber-JAR, the maven-shade-plugin with ServicesResourceTransformer merges META-INF/services/ files from all dependency JARs. Without it, gRPC service registrations can be silently dropped, causing the IronPDF engine to fail to initialize.
What timeout and memory settings are required for Google Cloud Functions running IronPDF?
Set the function timeout to 330 seconds, memory to at least 2048 MB, and ephemeral storage to at least 1024 MB. Chromium initialization on a cold start can take 60 to 90 seconds, and the engine requires substantial memory to render complex HTML pages.
Why must Settings.setIronPdfEngineWorkingDirectory point to /tmp/ on Google Cloud?
The /tmp/ directory is the only writable and executable path available in most Google Cloud Function runtimes. IronPDF needs to extract its engine binary and write temporary files to this location. Without this setting, the engine cannot find a suitable extraction target and will fail to start.
Why does the Dockerfile need RUN chmod 777 /tmp/?
IronPDF's engine binary must be both written and executed from /tmp/. The default permissions on /tmp/ in some base images do not include execute permission for all users. The chmod 777 command ensures the function runtime user can extract and launch the binary.
When should grpc-okhttp be used instead of grpc-netty-shaded?
grpc-netty-shaded is recommended for production because it provides a more complete HTTP/2 implementation. grpc-okhttp is a lighter alternative useful when minimizing Docker image size is a priority. Either transport works with IronPDF for Java on Google Cloud Functions.

