Class PdfDocument
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
poolManagerIBrowserPoolManagerThe shared browser pool manager.
Methods
ConfigureFonts(string)
public PdfDocument ConfigureFonts(string fontDirectoryPath)
Parameters
fontDirectoryPathstring
Returns
CreateFromGlobalPool()
public static PdfDocument CreateFromGlobalPool()
Returns
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
disposingbool
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
EmulateMediaType(CssMediaType)
public PdfDocument EmulateMediaType(CssMediaType mediaType)
Parameters
mediaTypeCssMediaType
Returns
GenerateAsync()
public Task<byte[]> GenerateAsync()
Returns
Landscape(bool)
Sets the PDF output orientation to Landscape. Default is Portrait (false).
public PdfDocument Landscape(bool enabled = true)
Parameters
enabledboolTrue for Landscape, False for Portrait.
Returns
RunJavaScript(string)
public PdfDocument RunJavaScript(string script)
Parameters
scriptstring
Returns
SaveAsAsync(string)
public Task SaveAsAsync(string outputPath)
Parameters
outputPathstring
Returns
SetMargins(MarginOptions)
public PdfDocument SetMargins(MarginOptions margins)
Parameters
marginsMarginOptions
Returns
SetMargins(double, MarginUnit)
public PdfDocument SetMargins(double all, MarginUnit unit = MarginUnit.Pixels)
Parameters
alldoubleunitMarginUnit
Returns
WaitFor(WaitOptions)
public PdfDocument WaitFor(WaitOptions waitStrategy)
Parameters
waitStrategyWaitOptions
Returns
WithCspBypass(bool)
public PdfDocument WithCspBypass(bool enable = true)
Parameters
enablebool
Returns
WithHtml(string)
public PdfDocument WithHtml(string html)
Parameters
htmlstring
Returns
WithUrl(string)
public PdfDocument WithUrl(string url)
Parameters
urlstring