Table of Contents

Class PdfDocument

Namespace
CobaltPdf.WebKit
Assembly
CobaltPDF.WebKit.dll

The rendered PDF artifact.

public class PdfDocument
Inheritance
PdfDocument
Inherited Members

Constructors

PdfDocument(byte[])

public PdfDocument(byte[] data)

Parameters

data byte[]

Properties

BinaryData

public byte[] BinaryData { get; }

Property Value

byte[]

Length

Size of the PDF in bytes.

public long Length { get; }

Property Value

long

PageCount

Number of pages in this PDF.

public int PageCount { get; }

Property Value

int

PeakRssBytes

Peak resident-set size, in bytes, observed across the WebKit render subprocess tree (python + WebProcess + NetworkProcess). Null when the renderer didn't emit metrics (e.g. running stub mode, or Docker without the metrics sidecar plumbed through the bind mount).

public long? PeakRssBytes { get; init; }

Property Value

long?

PeakRssMb

Convenience: PeakRssBytes rounded to MB.

public double? PeakRssMb { get; }

Property Value

double?

RenderMilliseconds

Wall-clock time the render subprocess took, in milliseconds. Includes page load, paint, PDF serialisation, and post-processing.

public long? RenderMilliseconds { get; init; }

Property Value

long?

SteadyRssBytes

Steady-state resident-set size, in bytes, sampled after the render finished, all WebKit child processes have exited, GObject finalisers have run, and the glibc allocator has trimmed empty arenas back to the kernel.

This is the number to compare apples-to-apples against Chromium's Working Set on Windows — both reflect physical RAM occupied "right now", excluding transient peaks during page load + serialisation. For long-running pools, this is also what dictates whether you'll fit in your dyno's memory limit.

public long? SteadyRssBytes { get; init; }

Property Value

long?

SteadyRssMb

Convenience: SteadyRssBytes rounded to MB.

public double? SteadyRssMb { get; }

Property Value

double?

Methods

ExtractPage(int)

Extracts a single page (0-based) into a new PdfDocument, preserving its fonts, images and vector content.

public PdfDocument ExtractPage(int pageIndex)

Parameters

pageIndex int

Returns

PdfDocument

ExtractPages(IEnumerable<int>)

Extracts an arbitrary set of pages (0-based; may be non-contiguous and in any order) into a new document.

public PdfDocument ExtractPages(IEnumerable<int> pageIndices)

Parameters

pageIndices IEnumerable<int>

Returns

PdfDocument

ExtractPages(int, int)

Extracts an inclusive range of pages (0-based) into a new document.

public PdfDocument ExtractPages(int startIndex, int endIndex)

Parameters

startIndex int
endIndex int

Returns

PdfDocument

FromBytes(byte[])

Wraps existing PDF bytes for page operations.

public static PdfDocument FromBytes(byte[] data)

Parameters

data byte[]

Returns

PdfDocument

FromFile(string)

Loads an existing PDF from disk (e.g. to split a file you didn't render).

public static PdfDocument FromFile(string path)

Parameters

path string

Returns

PdfDocument

GetStream()

Returns a stream of the PDF data for attachments / HTTP responses.

public Stream GetStream()

Returns

Stream

Merge(params PdfDocument[])

Merges multiple PDFs into one, in order (the inverse of splitting).

public static PdfDocument Merge(params PdfDocument[] documents)

Parameters

documents PdfDocument[]

Returns

PdfDocument

SaveAs(string)

Saves the PDF to path and returns this instance for chaining.

public PdfDocument SaveAs(string path)

Parameters

path string

Returns

PdfDocument

SaveAsAsync(string)

Asynchronously saves the PDF and returns this instance for chaining.

public Task<PdfDocument> SaveAsAsync(string path)

Parameters

path string

Returns

Task<PdfDocument>

SplitIntoPages()

Splits this PDF into one single-page PdfDocument per page.

public IReadOnlyList<PdfDocument> SplitIntoPages()

Returns

IReadOnlyList<PdfDocument>