CobaltPDF.Requests 1.1.0

Prefix Reserved
dotnet add package CobaltPDF.Requests --version 1.1.0
                    
NuGet\Install-Package CobaltPDF.Requests -Version 1.1.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.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CobaltPDF.Requests" Version="1.1.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.1.0
                    
#r "nuget: CobaltPDF.Requests, 1.1.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.1.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.1.0
                    
Install as a Cake Addin
#tool nuget:?package=CobaltPDF.Requests&version=1.1.0
                    
Install as a Cake Tool

CobaltPDF.Requests

A lightweight, dependency-free companion package to CobaltPDF.

Install this package on the client (your web app, API gateway, mobile backend, etc.) to build and send PDF generation requests — without pulling in Chromium, Playwright, or any other heavy dependency. The CobaltPDF server handles the actual rendering.


Installation

dotnet add package CobaltPDF.Requests

How it works

Package Install on Responsibility
CobaltPDF.Requests Client Build and send PdfRequest
CobaltPDF Rendering server / Azure Function Receive, execute, return PDF

Both packages share the same PdfRequest model. The server-side CobaltPDF package provides a request.ExecuteAsync(engine) extension method that maps every property back to the fluent API automatically.


Quick start

// Client — only CobaltPDF.Requests installed
var request = new PdfRequest
{
    Url         = "https://myapp.com/invoice/42",
    Landscape   = true,
    PaperFormat = "A4",
    Metadata    = new() { Title = "Invoice #42", Author = "Billing System" }
};

var response = await httpClient.PostAsJsonAsync("/api/pdf", request);
var pdfBytes = await response.Content.ReadAsByteArrayAsync();

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" Paper size: "A4", "A3", "Letter", "Legal", "Tabloid", etc.
Margins PdfRequestMargins? null Page margins (null = CobaltPDF default of 1 cm).
Grayscale bool false Render in grayscale.
PrintBackground bool true Include CSS background colours and images.
MediaType string "screen" CSS media type to emulate: "screen" or "print".

Headers & footers

Property Type Description
Header string? HTML template printed at the top of every page. Supports <span class='pageNumber'> and <span class='totalPages'>.
Footer string? HTML template printed at the bottom of every page. Same token support as Header.

Watermark

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

Wait strategy

Property Type Default Description
WaitStrategy string "networkIdle" When to capture. See Wait strategies below.
WaitTimeoutMs int 30000 Timeout in ms for the wait strategy.

JavaScript

Property Type Default Description
CustomJs string? null JavaScript executed after page load, before capture.
BypassCsp bool false Bypass Content Security Policy (required when injecting scripts into strict pages).

HTTP headers

Property Type Default Description
UserAgent string? null Overrides the browser User-Agent for every request. null uses Chromium's default.
ExtraHeaders Dictionary<string, string> {} Additional HTTP headers sent with every request (navigation + sub-resources).
var request = new PdfRequest
{
    Url       = "https://example.com",
    UserAgent = "Mozilla/5.0 (compatible; MyBot/1.0)",
    ExtraHeaders = new()
    {
        ["Authorization"]  = "Bearer eyJ...",
        ["Accept-Language"] = "en-GB",
        ["X-Api-Key"]      = "secret"
    }
};

Cookies & storage

Property Type Default Description
Cookies List<PdfRequestCookie> [] Cookies injected before navigation.
LocalStorage Dictionary<string, string> {} Key/value pairs written to localStorage before the page loads.
SessionStorage Dictionary<string, string> {} Key/value pairs written to sessionStorage before the page loads.
var request = new PdfRequest
{
    Url     = "https://example.com",
    Cookies = [new() { Name = "session", Value = "abc123" }],
    LocalStorage = new() { ["theme"] = "dark" }
};

Lazy loading

Property Type Default Description
LazyLoadPages int? null Number of viewport-heights to scroll before capture. null = disabled.
LazyLoadDelayMs int 200 Pause between each scroll step (ms).

Encryption

Property Type Description
Encryption PdfRequestEncryption? Password-protect the output PDF. null = no encryption.
Encryption = new()
{
    UserPassword     = "open123",
    OwnerPassword    = "admin456", // optional — random generated if omitted
    AllowPrinting    = true,
    AllowCopying     = false,
    AllowModification = false
}

Metadata

Property Type Description
Metadata PdfRequestMetadata? Descriptive metadata embedded in the PDF document properties.
Metadata = new()
{
    Title    = "Invoice #42",
    Author   = "Billing System",
    Subject  = "Monthly invoice",
    Keywords = "invoice, billing",
    Creator  = "MyApp"
}

Supporting types

PdfRequestMargins

All values are CSS length strings: "10mm", "1cm", "0.5in", "20px".

Margins = new()
{
    Top    = "10mm",
    Bottom = "10mm",
    Left   = "15mm",
    Right  = "15mm"
}

PdfRequestCookie

Property Type Default Description
Name string (required) Cookie name.
Value string (required) Cookie value.
Domain string? null Domain scope. null = inferred from the rendered URL.
Path string "/" Cookie path.
Expires DateTime? null Expiry. null = session cookie.
Secure bool true HTTPS-only.
HttpOnly bool false Inaccessible to JavaScript.

Watermark

Property Type Default Description
Html string (required) HTML markup for the watermark (inline CSS supported).
Rotation int 0 Clockwise rotation in degrees.
Opacity double 0.5 0.0 (transparent) to 1.0 (opaque).
Vertical string "middle" "top", "middle", or "bottom".
Horizontal string "center" "left", "center", or "right".

Wait strategies

Value Description
"networkIdle" Wait until no network requests for 500 ms (default).
"signal" Wait for window.cobaltNotifyRender() to be called from CustomJs.
"selector:#my-id" Wait until the CSS selector is present in the DOM.
"js:window.myApp.ready===true" Poll a JavaScript expression until it returns truthy.
"delay:2000" Fixed delay in milliseconds.

PdfResponse

The server returns a PdfResponse after a successful render.

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

Helpers:

byte[]       bytes  = response.ToBytes();
MemoryStream stream = response.ToStream();

Full example

using CobaltPdf.Requests;

var request = new PdfRequest
{
    Url         = "https://myapp.com/invoice/42",
    Landscape   = false,
    PaperFormat = "A4",
    MediaType   = "print",

    // HTTP headers
    UserAgent    = "Mozilla/5.0 (compatible; InvoiceBot/1.0)",
    ExtraHeaders = new()
    {
        ["Authorization"]   = "Bearer eyJ...",
        ["Accept-Language"] = "en-GB"
    },

    // Auth cookie
    Cookies = [new() { Name = "session", Value = "abc123" }],

    // Wait for React app to signal readiness
    WaitStrategy = "signal",
    CustomJs     = "window.cobaltNotifyRender();",

    // PDF metadata
    Metadata = new()
    {
        Title  = "Invoice #42",
        Author = "Billing System"
    },

    // Password protect
    Encryption = new() { UserPassword = "open123" }
};

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

var pdfResponse = await httpResponse.Content.ReadFromJsonAsync<PdfResponse>();
await File.WriteAllBytesAsync("invoice.pdf", pdfResponse!.ToBytes());

License

See the CobaltPDF licensing page for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 57 2/22/2026
1.0.1 46 2/22/2026