Paragraph Class

Represents a paragraph of text.
Inheritance Hierarchy

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public class Paragraph : CompositeNode

The Paragraph type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleParagraph
Initializes a new instance of the Paragraph class.
Properties
  NameDescription
Public propertyCode exampleBreakIsStyleSeparator
True if this paragraph break is a Style Separator. A style separator allows one paragraph to consist of parts that have different paragraph styles.
Public propertyCode exampleChildNodes
Gets all immediate child nodes of this node.
(Inherited from CompositeNode.)
Public propertyCode exampleCount
Gets the number of immediate children of this node.
(Inherited from CompositeNode.)
Public propertyCode exampleDocument
Gets the document to which this node belongs.
(Inherited from Node.)
Public propertyCode exampleFirstChild
Gets the first child of the node.
(Inherited from CompositeNode.)
Public propertyCode exampleFrameFormat
Provides access to the paragraph formatting properties.
Public propertyCode exampleHasChildNodes
Returns true if this node has any child nodes.
(Inherited from CompositeNode.)
Public propertyCode exampleIsComposite
Returns true as this node can have child nodes.
(Inherited from CompositeNode.)
Public propertyCode exampleIsDeleteRevision
Returns true if this object was deleted in Microsoft Word while change tracking was enabled.
Public propertyCode exampleIsEndOfCell
True if this paragraph is the last paragraph in a Cell; false otherwise.
Public propertyCode exampleIsEndOfDocument
True if this paragraph is the last paragraph in the last section of the document.
Public propertyCode exampleIsEndOfHeaderFooter
True if this paragraph is the last paragraph in the HeaderFooter (main text story) of a Section; false otherwise.
Public propertyCode exampleIsEndOfSection
True if this paragraph is the last paragraph in the Body (main text story) of a Section; false otherwise.
Public propertyCode exampleIsFormatRevision
Returns true if formatting of the object was changed in Microsoft Word while change tracking was enabled.
Public propertyCode exampleIsInCell
True if this paragraph is an immediate child of Cell; false otherwise.
Public propertyCode exampleIsInsertRevision
Returns true if this object was inserted in Microsoft Word while change tracking was enabled.
Public propertyCode exampleIsListItem
True when the paragraph is an item in a bulleted or numbered list in original revision.
Public propertyCode exampleIsMoveFromRevision
Returns true if this object was moved (deleted) in Microsoft Word while change tracking was enabled.
Public propertyCode exampleIsMoveToRevision
Returns true if this object was moved (inserted) in Microsoft Word while change tracking was enabled.
Public propertyCode exampleLastChild
Gets the last child of the node.
(Inherited from CompositeNode.)
Public propertyCode exampleListFormat
Provides access to the list formatting properties of the paragraph.
Public propertyCode exampleListLabel
Gets a ListLabel object that provides access to list numbering value and formatting for this paragraph.
Public propertyCode exampleNextSibling
Gets the node immediately following this node.
(Inherited from Node.)
Public propertyCode exampleNodeType
Returns NodeType.Paragraph.
(Overrides NodeNodeType.)
Public propertyCode exampleParagraphBreakFont
Provides access to the font formatting of the paragraph break character.
Public propertyCode exampleParagraphFormat
Provides access to the paragraph formatting properties.
Public propertyCode exampleParentNode
Gets the immediate parent of this node.
(Inherited from Node.)
Public propertyCode exampleParentSection
Retrieves the parent Section of the paragraph.
Public propertyCode exampleParentStory
Retrieves the parent section-level story that can be Body or HeaderFooter.
Public propertyCode examplePreviousSibling
Gets the node immediately preceding this node.
(Inherited from Node.)
Public propertyCode exampleRange
Returns a Range object that represents the portion of a document that is contained in this node.
(Inherited from Node.)
Public propertyCode exampleRuns
Provides access to the typed collection of pieces of text inside the paragraph.
Methods
  NameDescription
Public methodCode exampleAccept
Accepts a visitor.
(Overrides NodeAccept(DocumentVisitor).)
Public methodCode exampleAppendChild
Adds the specified node to the end of the list of child nodes for this node.
(Inherited from CompositeNode.)
Public methodCode exampleAppendField(String)
Appends a field to this paragraph.
Public methodCode exampleAppendField(String, String)
Appends a field to this paragraph.
Public methodCode exampleAppendField(FieldType, Boolean)
Appends a field to this paragraph.
Public methodCode exampleClone (Inherited from Node.)
Public methodEquals (Inherited from Object.)
Public methodCode exampleGetAncestor(Type)
Gets the first ancestor of the specified object type.
(Inherited from Node.)
Public methodCode exampleGetAncestor(NodeType)
Gets the first ancestor of the specified NodeType.
(Inherited from Node.)
Public methodCode exampleGetChild
Returns an Nth child node that matches the specified type.
(Inherited from CompositeNode.)
Public methodCode exampleGetChildNodes
Returns a live collection of child nodes that match the specified type.
(Inherited from CompositeNode.)
Public methodCode exampleGetEffectiveTabStops
Returns array of all tab stops applied to this paragraph, including applied indirectly by styles or lists.
Public methodCode exampleGetEnumerator
Provides support for the for each style iteration over the child nodes of this node.
(Inherited from CompositeNode.)
Public methodGetHashCode (Inherited from Object.)
Public methodCode exampleGetText
Gets the text of this paragraph including the end of paragraph character.
(Overrides CompositeNodeGetText.)
Public methodGetType (Inherited from Object.)
Public methodCode exampleIndexOf
Returns the index of the specified child node in the child node array.
(Inherited from CompositeNode.)
Public methodCode exampleInsertAfter
Inserts the specified node immediately after the specified reference node.
(Inherited from CompositeNode.)
Public methodCode exampleInsertBefore
Inserts the specified node immediately before the specified reference node.
(Inherited from CompositeNode.)
Public methodCode exampleInsertField(String, Node, Boolean)
Inserts a field into this paragraph.
Public methodCode exampleInsertField(String, String, Node, Boolean)
Inserts a field into this paragraph.
Public methodCode exampleInsertField(FieldType, Boolean, Node, Boolean)
Inserts a field into this paragraph.
Public methodCode exampleJoinRunsWithSameFormatting
Joins runs with the same formatting in the paragraph.
Public methodCode exampleNextPreOrder
Gets next node according to the pre-order tree traversal algorithm.
(Inherited from Node.)
Public methodCode examplePrependChild
Adds the specified node to the beginning of the list of child nodes for this node.
(Inherited from CompositeNode.)
Public methodCode examplePreviousPreOrder
Gets the previous node according to the pre-order tree traversal algorithm.
(Inherited from Node.)
Public methodCode exampleRemove
Removes itself from the parent.
(Inherited from Node.)
Public methodCode exampleRemoveAllChildren
Removes all the child nodes of the current node.
(Inherited from CompositeNode.)
Public methodCode exampleRemoveChild
Removes the specified child node.
(Inherited from CompositeNode.)
Public methodCode exampleRemoveSmartTags
Removes all SmartTag descendant nodes of the current node.
(Inherited from CompositeNode.)
Public methodCode exampleSelectNodes
Selects a list of nodes matching the XPath expression.
(Inherited from CompositeNode.)
Public methodCode exampleSelectSingleNode
Selects the first Node that matches the XPath expression.
(Inherited from CompositeNode.)
Public methodToString (Inherited from Object.)
Public methodCode exampleToString(SaveFormat)
Exports the content of the node into a string in the specified format.
(Inherited from Node.)
Public methodCode exampleToString(SaveOptions)
Exports the content of the node into a string using the specified save options.
(Inherited from Node.)
Remarks

Paragraph is a block-level node and can be a child of classes derived from Story or InlineStory.

Paragraph can contain any number of inline-level nodes and bookmarks.

The complete list of child nodes that can occur inside a paragraph consists of BookmarkStart, BookmarkEnd, FieldStart, FieldSeparator, FieldEnd, FormField, Comment, Footnote, Run, SpecialChar, Shape, GroupShape, SmartTag.

A valid paragraph in Microsoft Word always ends with a paragraph break character and a minimal valid paragraph consists just of a paragraph break. The Paragraph class automatically appends the appropriate paragraph break character at the end and this character is not part of the child nodes of the Paragraph, therefore a Paragraph can be empty.

Do not include the end of paragraph ControlChar.ParagraphBreak or end of cell ControlChar.Cell characters inside the text of the paragraph as it might make the paragraph invalid when the document is opened in Microsoft Word.

Examples
Creates a simple document from scratch using the Aspose.Words object model.
// Create an "empty" document. Note that like in Microsoft Word, 
// the empty document has one section, body and one paragraph in it
Document doc = new Document();

// This truly makes the document empty. No sections (not possible in Microsoft Word)
doc.RemoveAllChildren();

// Create a new section node
// Note that the section has not yet been added to the document, 
// but we have to specify the parent document
Section section = new Section(doc);

// Append the section to the document
doc.AppendChild(section);

// Lets set some properties for the section
section.PageSetup.SectionStart = SectionStart.NewPage;
section.PageSetup.PaperSize = PaperSize.Letter;

// The section that we created is empty, lets populate it. The section needs at least the Body node
Body body = new Body(doc);
section.AppendChild(body);

// The body needs to have at least one paragraph
// Note that the paragraph has not yet been added to the document, 
// but we have to specify the parent document
// The parent document is needed so the paragraph can correctly work
// with styles and other document-wide information
Paragraph para = new Paragraph(doc);
body.AppendChild(para);

// We can set some formatting for the paragraph
para.ParagraphFormat.StyleName = "Heading 1";
para.ParagraphFormat.Alignment = ParagraphAlignment.Center;

// So far we have one empty paragraph in the document
// The document is valid and can be saved, but lets add some text before saving
// Create a new run of text and add it to our paragraph
Run run = new Run(doc);
run.Text = "Hello World!";
run.Font.Color = Color.Red;
para.AppendChild(run);

// As a matter of interest, you can retrieve text of the whole document and
// see that \x000c is automatically appended. \x000c is the end of section character
Console.WriteLine("Hello World!\x000c");

// Save the document
doc.Save(ArtifactsDir + "Section.CreateFromScratch.doc");
See Also