Skip to content
ComPDF

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);