PeachPDF

PeachPDF.PdfGenerator

PdfGenerator.CreateDocument(Action<IDocumentBuilder>, PdfGenerateConfig) Method

Creates a PDF document by building PeachPDF’s own internal box tree directly in C#, via handler, instead of parsing HTML/CSS - a QuestPDF-style declarative alternative to GeneratePdf(string, PdfGenerateConfig, PeachPdfCssContent) for a caller that wants a code-first API. handler never receives, generates, or parses any HTML/CSS text; every style is set directly as a typed value (PdfLength/PdfColor/etc.).

public System.Threading.Tasks.Task<PeachPDF.PeachPdfDocument> CreateDocument(System.Action<PeachPDF.Layout.IDocumentBuilder> handler, PeachPDF.PdfGenerateConfig? config=null);

Parameters

handler System.Action<IDocumentBuilder>

Builds the document’s pages via the given IDocumentBuilder.

config PdfGenerateConfig

The configuration to use for generation (page size/orientation/margins/etc. - see PdfGenerateConfig). A page built by IPageDescriptor that never calls .Size(...)/.Margin*(...) falls back to this config’s own page geometry, exactly like an HTML document’s own @page rule falls back to it. Defaults to A4 with 20pt margins when omitted - unlike PdfGenerateConfig’s own bare field defaults (Undefined, a 0pt page with no margins), which exist so the HTML path’s @page rule can tell “unset” from “explicitly zero”; a declarative document has no @page rule to defer to, so CreateDocument(handler) with no config at all needs a usable page size on its own to be a genuinely code-first, zero-config entry point.

Returns

System.Threading.Tasks.Task<PeachPdfDocument>