PeachPDF

PeachPDF.Layout.IDocumentBuilder

IDocumentBuilder.Stylesheet(PeachPdfCssContent) Method

Attaches a stylesheet to this document, so a caller-defined .class/#id/compound/ descendant selector rule matches and applies against every container tagged via Class(string)/Id(string)/Tag(string) across every Page(Action<IPageDescriptor>) in this document, and any @font-face/@property/ @font-palette-values/@page at-rule it declares takes effect too. Callable anywhere in the document-building callback, before, after, or interleaved with Page(Action<IPageDescriptor>) calls - Page(Action<IPageDescriptor>) itself only records its handler; every page’s actual content tree (and this stylesheet’s effect) is built afterward, once the whole callback has finished. Calling this more than once keeps only the last stylesheet; to combine several, merge them into one PeachPdfCssContent first via its own AddStyleSheet(string).

A bare type selector like div/img/a also matches this API’s own internal box structure (every anonymous container is tagged "div" by default, unless renamed via Tag(string)) - prefer class/id selectors, or Tag(string), for predictable targeting.

Precedence: an explicit builder call (e.g. Padding(PdfLength), Margin(PdfLength)/Size(PageSize)) always outranks a non-!important rule in this stylesheet - the same precedence an inline style="" attribute would have over an author stylesheet - but a matching !important rule always wins, matching real CSS. A base @page rule’s geometry only fills in what a page’s own Margin(PdfLength)/Size(PageSize) call left unset, ranking between an explicit call and the document’s PdfGenerateConfig default.

void Stylesheet(PeachPDF.PeachPdfCssContent content);

Parameters

content PeachPdfCssContent