CobaltPDF.Requests 1.3.0

Prefix Reserved
dotnet add package CobaltPDF.Requests --version 1.3.0
                    
NuGet\Install-Package CobaltPDF.Requests -Version 1.3.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CobaltPDF.Requests" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CobaltPDF.Requests" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="CobaltPDF.Requests" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CobaltPDF.Requests --version 1.3.0
                    
#r "nuget: CobaltPDF.Requests, 1.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CobaltPDF.Requests@1.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CobaltPDF.Requests&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=CobaltPDF.Requests&version=1.3.0
                    
Install as a Cake Tool

CobaltPDF.Requests

Lightweight, serialisable request and response models for CobaltPDF — the .NET HTML-to-PDF library.

Install this package in client applications (web APIs, mobile backends, microservices) that send PDF generation requests over HTTP to a CobaltPDF rendering service. No Chromium or Playwright dependency — just ~50 KB of models.

[Client Application]                        [PDF Rendering Service]
CobaltPDF.Requests (~50 KB)  ── HTTP POST ──▶  CobaltPDF (full library)
  PdfRequest  → JSON                            CobaltEngine + Chromium
  PdfResponse ← JSON                            request.ExecuteAsync(engine)
  No Chromium, No Playwright

Installation

Client (web app, mobile backend, other service):

dotnet add package CobaltPDF.Requests

Rendering service (Azure Function, ASP.NET Core, AWS Lambda, worker):

dotnet add package CobaltPDF
# CobaltPDF.Requests models are included automatically

Quick start — client

using CobaltPdf.Requests;
using System.Net.Http.Json;

var request = new PdfRequest
{
    Url         = "https://myapp.com/invoice/42",
    PaperFormat = "A4",
    Header      = "<div style='font-size:10px;text-align:center;width:100%'>My Company</div>",
    Footer      = "<div style='font-size:10px;text-align:center;width:100%'>" +
                  "Page <span class='pageNumber'></span> of <span class='totalPages'></span></div>",
    Metadata    = new() { Title = "Invoice #42", Author = "Billing System" },
    Encryption  = new() { UserPassword = "open123", AllowPrinting = true },
    Cookies     = [new() { Name = "session", Value = "abc123", Domain = "myapp.com" }]
};

var httpResponse = await httpClient.PostAsJsonAsync("https://pdf-service/api/pdf", request);
httpResponse.EnsureSuccessStatusCode();

// Option A — raw PDF bytes (Content-Type: application/pdf)
byte[] pdfBytes = await httpResponse.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("invoice.pdf", pdfBytes);

// Option B — PdfResponse JSON (Content-Type: application/json)
var pdfResponse = await httpResponse.Content.ReadFromJsonAsync<PdfResponse>();
byte[] pdfBytes2 = pdfResponse!.ToBytes();

Quick start — server

ASP.NET Core Minimal API

using CobaltPdf;
using CobaltPdf.Configuration;
using CobaltPdf.Extensions;
using CobaltPdf.Requests;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddCobaltPdf(o =>
{
    CloudEnvironment.ConfigureForDocker(o);
    o.MaxSize = Math.Max(2, Environment.ProcessorCount);
});

var app = builder.Build();

CobaltEngine.SetLicense(app.Configuration["CobaltPdf:LicenseKey"]!);
await CobaltEngine.PreWarmAsync();

// POST /api/pdf → raw PDF bytes
app.MapPost("/api/pdf", async (PdfRequest request, CobaltEngine renderer, CancellationToken ct) =>
{
    var pdf = await request.ExecuteAsync(renderer, ct);
    return Results.File(pdf.BinaryData, "application/pdf", "output.pdf");
});

// POST /api/pdf/json → PdfResponse JSON (service-to-service)
app.MapPost("/api/pdf/json", async (PdfRequest request, CobaltEngine renderer, CancellationToken ct) =>
{
    var pdf = await request.ExecuteAsync(renderer, ct);
    return Results.Ok(PdfResponse.FromBytes(pdf.BinaryData));
});

app.Run();

Azure Function (Isolated Worker)

[Function("GeneratePdf")]
public async Task<HttpResponseData> Run(
    [HttpTrigger(AuthorizationLevel.Function, "post", Route = "pdf")]
    HttpRequestData req, CancellationToken ct)
{
    var request = await req.ReadFromJsonAsync<PdfRequest>();
    var pdf     = await request!.ExecuteAsync(_renderer, ct);

    var response = req.CreateResponse(HttpStatusCode.OK);
    response.Headers.Add("Content-Type", "application/pdf");
    await response.Body.WriteAsync(pdf.BinaryData, ct);
    return response;
}

Note: Azure Functions Consumption Plan is not supported. Use the Premium Plan (EP1+) or Dedicated (App Service) Plan.


Client examples in other languages

TypeScript / JavaScript

const request = {
  url:         "https://myapp.com/invoice/42",
  paperFormat: "A4",
  landscape:   false,
  metadata:    { title: "Invoice #42", author: "Billing System" }
};

const response = await fetch("https://pdf-service/api/pdf", {
  method:  "POST",
  headers: { "Content-Type": "application/json" },
  body:    JSON.stringify(request)
});

const blob = await response.blob();
const url  = URL.createObjectURL(blob);
const a    = document.createElement("a");
a.href     = url;
a.download = "invoice.pdf";
a.click();

Python

import requests

payload = {
    "url":         "https://myapp.com/invoice/42",
    "paperFormat": "A4",
    "metadata":    { "title": "Invoice #42", "author": "Billing System" }
}

response = requests.post("https://pdf-service/api/pdf", json=payload)
response.raise_for_status()

with open("invoice.pdf", "wb") as f:
    f.write(response.content)

PdfRequest properties

Source (one required)

Property Type Description
Url string? URL to render. Mutually exclusive with Html.
Html string? Raw HTML to render. Mutually exclusive with Url.

Layout

Property Type Default Description
Landscape bool false Landscape orientation.
PaperFormat string "A4" "A4", "A3", "Letter", "Legal", "Tabloid".
Margins PdfRequestMargins? null (1 cm) Page margins as CSS lengths (e.g. "10mm", "1cm").
Grayscale bool false Render in grayscale.
PrintBackground bool true Include CSS background colours and images.
MediaType string "screen" CSS media type: "screen" or "print".

Headers & footers

Property Type Description
Header string? HTML header template. Supports <span class='pageNumber'>, <span class='totalPages'>, <span class='date'>.
Footer string? HTML footer template. Same token support as Header.

Watermark

Property Type Description
Watermark PdfRequestWatermark? Overlay applied to every page.

Wait strategy

Property Type Default Description
WaitStrategy string "networkIdle" When to capture. See values below.
WaitTimeoutMs int 30000 Timeout in ms.
Value Behaviour
"networkIdle" Wait until no network activity for 500 ms (default).
"signal" Wait for window.cobaltNotifyRender() from page JavaScript.
"selector:#my-id" Wait until the CSS selector is present and visible.
"js:window.ready===true" Poll a JavaScript expression until truthy.
"delay:2000" Fixed delay in milliseconds.

HTTP & authentication

Property Type Default Description
UserAgent string? null Browser User-Agent string.
ExtraHeaders Dictionary<string,string> {} HTTP headers sent with every request.
Cookies List<PdfRequestCookie> [] Cookies injected before navigation.
LocalStorage Dictionary<string,string> {} localStorage values set before load.
SessionStorage Dictionary<string,string> {} sessionStorage values set before load.

JavaScript

Property Type Default Description
CustomJs string? null JavaScript executed on the page before capture.
BypassCsp bool false Bypass Content Security Policy.

Lazy loading

Property Type Default Description
LazyLoadPages int? null Viewport-heights to scroll to trigger lazy content.
LazyLoadDelayMs int 200 Pause between scroll steps (ms).

Encryption

Property Type Default Description
Encryption.UserPassword string? null Password required to open the PDF.
Encryption.OwnerPassword string? null Full-access password.
Encryption.AllowPrinting bool true Allow printing.
Encryption.AllowCopying bool false Allow copying text.
Encryption.AllowModification bool false Allow editing.

Metadata

Property Type Description
Metadata.Title string? Document title (shown in PDF reader title bar).
Metadata.Author string? Author name.
Metadata.Subject string? Document subject.
Metadata.Keywords string? Comma-separated keywords.
Metadata.Creator string? Application that created the document.

PdfResponse

Returned by the rendering service after a successful render.

Property Type Description
Data string Base64-encoded PDF binary.
SizeBytes long Size of the PDF in bytes.
RenderedAt DateTime UTC timestamp of when the render completed.

Helpers:

byte[]       bytes  = response.ToBytes();   // decode to raw bytes
MemoryStream stream = response.ToStream();  // decode to a MemoryStream

Factory (server-side):

var response = PdfResponse.FromBytes(pdf.BinaryData);

Returning the PDF

Your endpoint can respond in two ways:

Raw bytes — application/pdf

Best for browser downloads, mobile apps, and direct file saves.

return Results.File(pdf.BinaryData, "application/pdf", "output.pdf");

JSON — PdfResponse

Best for service-to-service calls where the caller needs to process or store the PDF.

return Results.Ok(PdfResponse.FromBytes(pdf.BinaryData));

Platform summary

Platform Server package Preset Notes
Azure Functions Premium CobaltPDF ConfigureForAzure Do not use Consumption Plan
Azure App Service (Linux) CobaltPDF ConfigureForAzure Set license in App Settings
Azure Container Apps CobaltPDF ConfigureForDocker Standard Docker container
AWS ECS / Fargate CobaltPDF ConfigureForAwsEcs Recommended for sustained load
AWS Lambda CobaltPDF ConfigureForLowMemory Custom container; pool may restart
ASP.NET Core (Docker) CobaltPDF ConfigureForDocker Full control, any host

Security considerations

  • Authenticate every endpoint. The rendering service can reach any URL on its network — an unauthenticated endpoint is a security risk.
  • Whitelist allowed domains if you don't control all callers, to prevent SSRF.
  • Store license keys in secrets — Azure Key Vault, AWS Secrets Manager, or environment variables.
  • Do not expose Html rendering publicly without sanitisation — arbitrary HTML can be used to render internal URLs.

Documentation

Full deployment guides (Azure Functions, AWS Lambda, ECS/Fargate), the complete JSON schema, and working server examples are available at:

cobaltpdf.com/docs/articles/cobalt-requests.html


License

See the CobaltPDF website for licensing details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on CobaltPDF.Requests:

Package Downloads
CobaltPDF

A high-performance .NET library for creating pixel-perfect PDFs from HTML and URLs using a managed Chromium browser pool. Supports headers, footers, watermarks, encryption, metadata, cookies, custom JavaScript, lazy loading, and more. Targets .NET 6.0 and .NET 8.0+.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.0 75 3/1/2026
1.2.0 127 2/27/2026