import com.ironsoftware.ironpdf.Settings;import java.nio.file.Paths;// Point IronPDF at a writable directory in the Cloud Function runtimeSettings.setIronPdfEngineWorkingDirectory(Paths.get("/tmp/"));
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=Dockerfile# Use the official Google Cloud Functions Java 17 base imageFROM gcr.io/google-appengine/java17:latest# Install Chrome system dependencies required by IronPDF's rendering engineRUN 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 thereRUN chmod 777 /tmp/# Copy the compiled JAR and set the entry pointCOPY target/your-function.jar /app/function.jarCMD ["java", "-jar", "/app/function.jar"]
//: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"]
//:path=pom.xml<dependencies> <!-- Performance tracing — may be required by some gRPC versions --> <dependency> <groupId>io.perfmark</groupId> <artifactId>perfmark-api</artifactId> <version>0.26.0</version> </dependency> <!-- OkHttp-based gRPC transport — alternative to Netty for lighter images --> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-okhttp</artifactId> <version>1.50.2</version> </dependency> <!-- Netty-shaded gRPC transport — recommended for production deployments --> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-netty-shaded</artifactId> <version>1.50.2</version> </dependency></dependencies>
//:path=pom.xml
<dependencies>
<!-- Performance tracing — may be required by some gRPC versions -->
<dependency>
<groupId>io.perfmark</groupId>
<artifactId>perfmark-api</artifactId>
<version>0.26.0</version>
</dependency>
<!-- OkHttp-based gRPC transport — alternative to Netty for lighter images -->
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-okhttp</artifactId>
<version>1.50.2</version>
</dependency>
<!-- Netty-shaded gRPC transport — recommended for production deployments -->
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>1.50.2</version>
</dependency>
</dependencies>
//:path=/static-assets/pdf/content-code-examples/tutorials/google-cloud/configure-working-directory.javaimport 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/"));
}
}
Java
然后在您的Dockerfile中添加相应的权限命令:
//:path=Dockerfile# Ensure the IronPDF engine can extract and run binaries from /tmp/RUN chmod 777 /tmp/
//:path=Dockerfile
# Ensure the IronPDF engine can extract and run binaries from /tmp/
RUN chmod 777 /tmp/
grpc-netty-shaded推荐用于生产,因为它提供了更完整的HTTP/2实现。grpc-okhttp是一个较轻的替代方案,在最小化Docker镜像大小时非常有用。两种传输均可在Google Cloud Functions上的IronPDF for Java中使用。
How do I configure pom.xml for optimal performance in IronPDF deployments?
Ensure the `ironpdf-engine-linux-x64` artifact's version matches the core `ironpdf` library version in your pom.xml. This ensures compatibility and prevents runtime errors.
What troubleshooting steps should I take if my IronPDF function fails to initialize?
Verify that all Chromium dependencies are included in your Docker setup, check resource limits for sufficient allocation, and ensure that `/tmp/` permissions are correctly set in your Dockerfile.