For the complete documentation index, see llms.txt. This page is also available as Markdown.

Paragraphs and text

A Paragraph is the basic building block of a document. Its text flows automatically and wraps at the page margins, so you never position text yourself.

Add a paragraph

AddParagraph appends a paragraph to a document, a section, a table cell, a list item, a float or a shape text box. The overload taking a string is a shortcut for adding a paragraph and a single text run.

doc.AddParagraph("A paragraph is the basic building block of a document. " +
                 "Its text flows automatically and wraps at the page margins.");
doc.AddParagraph("A paragraph is the basic building block of a document. "
                 "Its text flows automatically and wraps at the page margins.");
doc.AddParagraph("A paragraph is the basic building block of a document. " +
    "Its text flows automatically and wraps at the page margins.")
doc.addParagraph("A paragraph is the basic building block of a document. "
        + "Its text flows automatically and wraps at the page margins.");
await doc.addParagraphWithText('A paragraph is the basic building block of a document. ' +
    'Its text flows automatically and wraps at the page margins.');
[doc AddParagraphWithText:@"A paragraph is the basic building block of a document. "
                           "Its text flows automatically and wraps at the page margins."];
$doc->AddParagraph("A paragraph is the basic building block of a document. " .
                   "Its text flows automatically and wraps at the page margins.");
doc.AddParagraph("A paragraph is the basic building block of a document. "
                 "Its text flows automatically and wraps at the page margins.")
doc.AddParagraph("A paragraph is the basic building block of a document. " +
                 "Its text flows automatically and wraps at the page margins.")
an example of a paragraph.

Text runs and character styling

A paragraph contains a sequence of TextRun objects. Each run carries its own character style, so mixed formatting is expressed by adding several runs. AddText returns the run it created, and GetTextStyledElement exposes the style.

An example of types of text like highlight, italics, bold.

Setting the style on the paragraph instead of a run establishes the default for everything the paragraph contains.

Justification

SetJustificationMode accepts a left (the default), center, or right justification value.

Example of justification.

Indents, spacing, and borders

SetTextIndent indents only the first line, while SetStartIndent and SetEndIndent indent the whole block. SetSpaceBefore and SetSpaceAfter add vertical space, and SetBorder draws a frame around the paragraph.

Example of spacing and borders around text.

Info

SetStartIndent and SetEndIndent are writing-direction aware. In a right-to-left paragraph the start indent applies to the right edge.

Tab stops

Tab stops align columns of text without the overhead of a table. Add explicit stops with AddTabStop, or set a repeating interval with SetDefaultTabStop.

Example of tabbing with text.

Use a table instead when the columns need borders, shading, or cells that wrap onto several lines.

AddHyperlink creates a text run with a link target attached. The visual styling is up to you. Links are not colored or underlined automatically.

Example of a hyperlink with text.

An existing run can be turned into a link with SetHyperlinkTarget.

Line breaks

A \n inside a text run forces a line break without starting a new paragraph, which is convenient for addresses and similar blocks.

Further Reading

  • Lists for automatically numbered paragraphs.

  • Tables for column layouts that need borders and shading.

Last updated

Was this helpful?