Skip to content
ComPDF

Core Concepts

Document Structure

The Layout API organizes document content using a tree structure:

CDocument (Document)
  ├─ CPage (Page)
  │   ├─ CDiv (Container)
  │   │   ├─ CParagraph (Paragraph)
  │   │   ├─ CTable (Table)
  │   │   ├─ CList (List)
  │   │   ├─ CImage (Image)
  │   │   ├─ CText (Text)
  │   │   └─ CLineSeparator (Separator)
  │   └─ ... (Other elements)
  └─ CStyle (Style)

Element Types

1. Container Elements

  • CDocument: Root container of the PDF document, can contain multiple pages.
  • CPage: Represents a page of the PDF, can contain various layout elements.
  • CDiv: Generic container element, similar to div in HTML, used to organize content.
  • CParagraph: Paragraph container, supports line spacing and first-line indentation.
  • CTable: Table element, supports cell merging, headers, and footers.
  • CCell: Table cell.
  • CList: List container, supports ordered and unordered lists.
  • CListItem: List item.

2. Content Elements

  • CText: Text element, can set font, color, size, etc.
  • CImage: Image element, supports various scaling modes.

3. Other Elements

  • CLineSeparator: Horizontal separator line.
  • CStyle: Reusable style definition.

Unit System

The Layout API uses the CUnitValue structure to represent dimension values, supporting two units:

csharp
// Point unit - 1 point = 1/72 inch
CUnitValue pointValue = CUnitValue.CreatePointValue(100f);

// Percentage unit
CUnitValue percentValue = CUnitValue.CreatePercentValue(50f);

Color System

Use the CColor structure to define RGBA colors:

csharp
// Create color using RGBA values
CColor color = new CColor(255, 0, 0, 255); // Red, fully opaque

// Use predefined colors
CColor black = CColor.Black;
CColor white = CColor.White;
CColor red = CColor.Red;