Table of Contents

Class PdfDocument

Namespace
CobaltPdf.Models
Assembly
CobaltPdf.dll

A document generator for creating PDFs from HTML or URLs. This class is designed to be used either as a transient, injected service (for high performance) or as a single-use object (for simple use cases).

public class PdfDocument : IDisposable, IAsyncDisposable
Inheritance
PdfDocument
Implements
Inherited Members

Constructors

PdfDocument()

Creates a new, single-use PDF document generator. This method is slower initially as it launches a new browser process, but subsequent calls on the same instance reuse that process.

public PdfDocument()

PdfDocument(IBrowserPoolManager)

Creates a new PDF document generator using a shared browser pool. This is the high-performance constructor, intended for use with Dependency Injection.

public PdfDocument(IBrowserPoolManager poolManager)

Parameters

poolManager IBrowserPoolManager

The shared browser pool manager.

Methods

ConfigureFonts(string)

public PdfDocument ConfigureFonts(string fontDirectoryPath)

Parameters

fontDirectoryPath string

Returns

PdfDocument

CreateFromGlobalPool()

public static PdfDocument CreateFromGlobalPool()

Returns

PdfDocument

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

DisposeAsyncCore()

protected virtual ValueTask DisposeAsyncCore()

Returns

ValueTask

EmulateMediaType(CssMediaType)

public PdfDocument EmulateMediaType(CssMediaType mediaType)

Parameters

mediaType CssMediaType

Returns

PdfDocument

GenerateAsync()

public Task<byte[]> GenerateAsync()

Returns

Task<byte[]>

Landscape(bool)

Sets the PDF output orientation to Landscape. Default is Portrait (false).

public PdfDocument Landscape(bool enabled = true)

Parameters

enabled bool

True for Landscape, False for Portrait.

Returns

PdfDocument

RunJavaScript(string)

public PdfDocument RunJavaScript(string script)

Parameters

script string

Returns

PdfDocument

SaveAsAsync(string)

public Task SaveAsAsync(string outputPath)

Parameters

outputPath string

Returns

Task

SetMargins(MarginOptions)

public PdfDocument SetMargins(MarginOptions margins)

Parameters

margins MarginOptions

Returns

PdfDocument

SetMargins(double, MarginUnit)

public PdfDocument SetMargins(double all, MarginUnit unit = MarginUnit.Pixels)

Parameters

all double
unit MarginUnit

Returns

PdfDocument

WaitFor(WaitOptions)

public PdfDocument WaitFor(WaitOptions waitStrategy)

Parameters

waitStrategy WaitOptions

Returns

PdfDocument

WithCspBypass(bool)

public PdfDocument WithCspBypass(bool enable = true)

Parameters

enable bool

Returns

PdfDocument

WithHtml(string)

public PdfDocument WithHtml(string html)

Parameters

html string

Returns

PdfDocument

WithUrl(string)

public PdfDocument WithUrl(string url)

Parameters

url string

Returns

PdfDocument