Skip to content
ComPDF
DemoSampleAPI ReferenceFAQ
New Release

Open-Source PDF SDK & AI Document Processing

Get the full self-hosted SDK and AI document processing on GitHub. One-click deploy to quickly build your document workflows.

Style Management

Creating and Using Styles

csharp
// Create style
CStyle headingStyle = document.CreateStyle();

// Set style properties (supports method chaining)
headingStyle.SetFontSize(18);
headingStyle.SetFontWeight(CFontWeight.Bold);
headingStyle.SetMarginBottom(10);
headingStyle.SetTextAlignment(CTextAlignment.Center);

// Apply style to element
CText heading = div.CreateText("Heading text");
heading.AddStyle(headingStyle);

// Element can also have multiple styles
CStyle colorStyle = document.CreateStyle();
colorStyle.SetFontColor(CColor.Red);
heading.AddStyle(colorStyle);