Click or drag to resize
Pdf Library for .NET

Deployment to Google Cloud Run

Google Cloud Run runs container images and scales them with the traffic. SelectPdf runs there in a Linux image built from the standard mcr.microsoft.com/dotnet/aspnet image, as its non-root user, in both execution environments, and also as a Cloud Run function.

The image

Reference the three packages in the application:

XML
<ItemGroup>
  <PackageReference Include="SelectPdf.Universal" Version="26.4.0" />
  <PackageReference Include="SelectPdf.Universal.Native.linux-x64"
                    Version="26.4.0" />
  <PackageReference Include="SelectPdf.Universal.Fonts" Version="26.4.0" />
</ItemGroup>

and build the image as in Azure Container Apps or Deployment with Docker; Cloud Run passes the port in the PORT environment variable (8080 by default).

Step by step

1. Set up the project (once): create a project in the Google Cloud console, link a billing account, install the gcloud CLI, then:

gcloud auth login
gcloud config set project YOUR_PROJECT_ID
gcloud config set run/region europe-north1
gcloud services enable run.googleapis.com artifactregistry.googleapis.com
gcloud artifacts repositories create selectpdf \
    --repository-format=docker --location=europe-north1
gcloud auth configure-docker europe-north1-docker.pkg.dev

2. Build and push the image:

docker build --platform linux/amd64 \
    -t europe-north1-docker.pkg.dev/YOUR_PROJECT_ID/selectpdf/myapp .
docker push europe-north1-docker.pkg.dev/YOUR_PROJECT_ID/selectpdf/myapp

3. Deploy:

gcloud run deploy myapp \
    --image europe-north1-docker.pkg.dev/YOUR_PROJECT_ID/selectpdf/myapp \
    --cpu 2 --memory 4Gi --timeout 300 --concurrency 8 \
    --no-allow-unauthenticated
  • --cpu 2 --memory 4Gi - with 2 GiB a heavy page can run the instance out of memory; Cloud Run then restarts it and the request fails with HTTP 503.

  • --concurrency 8 - the number of pages SelectPdf converts at once by default.

  • --no-allow-unauthenticated - callers need an identity token; use --allow-unauthenticated only for a public service.

  • --execution-environment gen2 is optional: SelectPdf runs in the default (first generation) environment and in the second generation alike.

Cloud Run functions

The same code runs as a Cloud Run function (gcloud functions deploy --gen2 --runtime dotnet8, with the Google.Cloud.Functions.Hosting package and an IHttpFunction class). Google builds the function from source, restoring the SelectPdf packages like any other, and runs it on Ubuntu as a non-root user. Use at least --memory 2Gi and --cpu 2.

What to expect

Measured in October 2026 (europe-north1, 2 vCPU): every conversion succeeded in both execution environments and as a function, with every language rendered. A warm instance converts selectpdf.com in about 1.4 seconds; the first conversion of a new instance takes 5 to 10 seconds. Cloud Run keeps an idle instance for a while, and --min-instances 1 keeps one ready. A response can be up to 32 MB, so large PDFs are returned directly.

Sample

The official samples include this deployment, with a step-by-step README, in the cloud/google-cloud-run folder of the edition's samples.

See Also