Skip to content
ComPDF

Text and Paragraphs

Creating Text

csharp
// Create text in div
CText text = div.CreateText("This is some text");

// Set font properties
text.SetFontFamily("Arial");
text.SetFontSize(14);
text.SetFontColor(new CColor(0, 0, 0, 255));
text.SetFontWeight(CFontWeight.Bold);
text.SetFontStyle(CFontStyle.Italic);

// Set text decoration
text.SetUnderline(CUnderline.Black);

// Set character and word spacing
text.SetCharacterSpacing(0.5f);
text.SetWordSpacing(2.0f);

Creating Paragraphs

csharp
// Create empty paragraph
CParagraph paragraph = div.CreateParagraph();

// Or create paragraph with initial text
CParagraph paragraph = div.CreateParagraph("Paragraph text content");

// Add text to paragraph
CText text1 = paragraph.CreateText("First part of text");
CText text2 = paragraph.CreateText("Second part of text");
text2.SetFontWeight(CFontWeight.Bold);

// Set line spacing
paragraph.SetFixedLeading(20f); // Fixed line spacing
// or
paragraph.SetMultipliedLeading(1.5f); // Relative line spacing (1.5x)

// Set first-line indent
paragraph.SetFirstLineIndent(32f);

// Set text alignment
paragraph.SetTextAlignment(CTextAlignment.Justify);

Text Alignment Options

csharp
paragraph.SetTextAlignment(CTextAlignment.Left);    // Left align
paragraph.SetTextAlignment(CTextAlignment.Center);  // Center align
paragraph.SetTextAlignment(CTextAlignment.Right);   // Right align
paragraph.SetTextAlignment(CTextAlignment.Justify); // Justify