|
java.lang.Object
Node
CompositeNode
com.aspose.words.Paragraph
- All Implemented Interfaces:
- java.lang.Iterable, java.lang.Cloneable, java.lang.Iterable
public class Paragraph - extends CompositeNode
Represents a paragraph of text.
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.PARAGRAPH_BREAK
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. Example: 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.getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
section.getPageSetup().setPaperSize(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.getParagraphFormat().setStyleName("Heading 1");
para.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
// So far we have one empty pararagraph 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.setText("Hello World!");
run.getFont().setColor(Color.RED);
para.appendChild(run);
// As a matter of interest, you can retrieve text of the whole document and
// see that \u000c is automatically appended. \u000c is the end of section character.
Assert.assertEquals("Hello World!\u000c", doc.getText());
// Save the document.
doc.save(getMyDir() + "Section.CreateFromScratch Out.doc");
|
Constructor Summary |
Paragraph(Document doc)
Initializes a new instance of the Paragraph class.
|
|