com.aspose.words

Class ParagraphFormat

  • java.lang.Object
    • com.aspose.words.ParagraphFormat
public class ParagraphFormat 
extends java.lang.Object

Represents all the formatting for a paragraph.

Example:

Shows how to construct an Aspose.Words document by hand.
Document doc = new Document();

// A blank document contains one section, one body and one paragraph.
// Call the "RemoveAllChildren" method to remove all those nodes,
// and end up with a document node with no children.
doc.removeAllChildren();

// This document now has no composite child nodes that we can add content to.
// If we wish to edit it, we will need to repopulate its node collection.
// First, create a new section, and then append it as a child to the root document node.
Section section = new Section(doc);
doc.appendChild(section);

// Set some page setup properties for the section.
section.getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
section.getPageSetup().setPaperSize(PaperSize.LETTER);

// A section needs a body, which will contain and display all its contents
// on the page between the section's header and footer.
Body body = new Body(doc);
section.appendChild(body);

// Create a paragraph, set some formatting properties, and then append it as a child to the body.
Paragraph para = new Paragraph(doc);

para.getParagraphFormat().setStyleName("Heading 1");
para.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);

body.appendChild(para);

// Finally, add some content to do the document. Create a run,
// set its appearance and contents, and then append it as a child to the paragraph.
Run run = new Run(doc);
run.setText("Hello World!");
run.getFont().setColor(Color.RED);
para.appendChild(run);

Assert.assertEquals("Hello World!", doc.getText().trim());

doc.save(getArtifactsDir() + "Section.CreateManually.docx");

Property Getters/Setters Summary
booleangetAddSpaceBetweenFarEastAndAlpha()
void
           Gets or sets a flag indicating whether inter-character spacing is automatically adjusted between regions of Latin text and regions of East Asian text in the current paragraph.
booleangetAddSpaceBetweenFarEastAndDigit()
void
           Gets or sets a flag indicating whether inter-character spacing is automatically adjusted between regions of numbers and regions of East Asian text in the current paragraph.
intgetAlignment()
void
setAlignment(intvalue)
           Gets or sets text alignment for the paragraph. The value of the property is ParagraphAlignment integer constant.
booleangetBidi()
void
setBidi(booleanvalue)
           Gets or sets whether this is a right-to-left paragraph.
BorderCollectiongetBorders()
Gets collection of borders of the paragraph.
doublegetCharacterUnitFirstLineIndent()
void
           Gets or sets the value (in characters) for the first-line or hanging indent.

Use positive values to set the first-line indent, and negative values to set the hanging indent.

doublegetCharacterUnitLeftIndent()
void
           Gets or sets the left indent value (in characters) for the specified paragraphs.
doublegetCharacterUnitRightIndent()
void
           Gets or sets the right indent value (in characters) for the specified paragraphs.
intgetDropCapPosition()
void
           Gets or sets the position for a drop cap text. The value of the property is DropCapPosition integer constant.
booleangetFarEastLineBreakControl()
void
           Gets or sets a flag indicating whether East Asian line-breaking rules are applied to the current paragraph.
doublegetFirstLineIndent()
void
setFirstLineIndent(doublevalue)
           Gets or sets the value (in points) for a first line or hanging indent.

Use positive values to set the first-line indent, and negative values to set the hanging indent.

booleangetHangingPunctuation()
void
setHangingPunctuation(booleanvalue)
           Gets or sets a flag indicating whether hanging punctuation is enabled for the current paragraph.
booleanisHeading()
True when the paragraph style is one of the built-in Heading styles.
booleanisListItem()
True when the paragraph is an item in a bulleted or numbered list.
booleangetKeepTogether()
void
setKeepTogether(booleanvalue)
           True if all lines in the paragraph are to remain on the same page.
booleangetKeepWithNext()
void
setKeepWithNext(booleanvalue)
           True if the paragraph is to remains on the same page as the paragraph that follows it.
doublegetLeftIndent()
void
setLeftIndent(doublevalue)
           Gets or sets the value (in points) that represents the left indent for paragraph.
doublegetLineSpacing()
void
setLineSpacing(doublevalue)
           Gets or sets the line spacing (in points) for the paragraph.
intgetLineSpacingRule()
void
           Gets or sets the line spacing for the paragraph. The value of the property is LineSpacingRule integer constant.
intgetLinesToDrop()
void
setLinesToDrop(intvalue)
           Gets or sets the number of lines of the paragraph text used to calculate the drop cap height.
doublegetLineUnitAfter()
void
setLineUnitAfter(doublevalue)
           Gets or sets the amount of spacing (in gridlines) after the paragraphs.
doublegetLineUnitBefore()
void
setLineUnitBefore(doublevalue)
           Gets or sets the amount of spacing (in gridlines) before the paragraphs.
booleangetNoSpaceBetweenParagraphsOfSameStyle()
void
           When true, SpaceBefore and SpaceAfter will be ignored between the paragraphs of the same style.
intgetOutlineLevel()
void
setOutlineLevel(intvalue)
           Specifies the outline level of the paragraph in the document. The value of the property is OutlineLevel integer constant.
booleangetPageBreakBefore()
void
setPageBreakBefore(booleanvalue)
           True if a page break is forced before the paragraph.
doublegetRightIndent()
void
setRightIndent(doublevalue)
           Gets or sets the value (in points) that represents the right indent for paragraph.
ShadinggetShading()
Returns a Shading object that refers to the shading formatting for the paragraph.
booleangetSnapToGrid()
void
setSnapToGrid(booleanvalue)
           Specifies whether the current paragraph should use the document grid lines per page settings when laying out the contents in the paragraph.
doublegetSpaceAfter()
void
setSpaceAfter(doublevalue)
           Gets or sets the amount of spacing (in points) after the paragraph.
booleangetSpaceAfterAuto()
void
setSpaceAfterAuto(booleanvalue)
           True if the amount of spacing after the paragraph is set automatically.
doublegetSpaceBefore()
void
setSpaceBefore(doublevalue)
           Gets or sets the amount of spacing (in points) before the paragraph.
booleangetSpaceBeforeAuto()
void
setSpaceBeforeAuto(booleanvalue)
           True if the amount of spacing before the paragraph is set automatically.
StylegetStyle()
void
setStyle(Style value)
           Gets or sets the paragraph style applied to this formatting.
intgetStyleIdentifier()
void
           Gets or sets the locale independent style identifier of the paragraph style applied to this formatting. The value of the property is StyleIdentifier integer constant.
java.lang.StringgetStyleName()
void
setStyleName(java.lang.Stringvalue)
           Gets or sets the name of the paragraph style applied to this formatting.
booleangetSuppressAutoHyphens()
void
           Specifies whether the current paragraph should be exempted from any hyphenation which is applied in the document settings.
booleangetSuppressLineNumbers()
void
           Specifies whether the current paragraph's lines should be exempted from line numbering which is applied in the parent section.
TabStopCollectiongetTabStops()
Gets the collection of custom tab stops defined for this object.
booleangetWidowControl()
void
setWidowControl(booleanvalue)
           True if the first and last lines in the paragraph are to remain on the same page as the rest of the paragraph.
booleangetWordWrap()
void
setWordWrap(booleanvalue)
           If this property is false, Latin text in the middle of a word can be wrapped for the current paragraph. Otherwise Latin text is wrapped by whole words.
 
Method Summary
voidclearFormatting()
Resets to default paragraph formatting.
 

    • Property Getters/Setters Detail

      • getAddSpaceBetweenFarEastAndAlpha/setAddSpaceBetweenFarEastAndAlpha

        public boolean getAddSpaceBetweenFarEastAndAlpha() / public void setAddSpaceBetweenFarEastAndAlpha(boolean value)
        
        Gets or sets a flag indicating whether inter-character spacing is automatically adjusted between regions of Latin text and regions of East Asian text in the current paragraph.

        Example:

        Shows how to insert a paragraph into the document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Font font = builder.getFont();
        font.setSize(16.0);
        font.setBold(true);
        font.setColor(Color.BLUE);
        font.setName("Arial");
        font.setUnderline(Underline.DASH);
        
        ParagraphFormat paragraphFormat = builder.getParagraphFormat();
        paragraphFormat.setFirstLineIndent(8.0);
        paragraphFormat.setAlignment(ParagraphAlignment.JUSTIFY);
        paragraphFormat.setAddSpaceBetweenFarEastAndAlpha(true);
        paragraphFormat.setAddSpaceBetweenFarEastAndDigit(true);
        paragraphFormat.setKeepTogether(true);
        
        // The "Writeln" method ends the paragraph after appending text
        // and then starts a new line, adding a new paragraph.
        builder.writeln("Hello world!");
        
        Assert.assertTrue(builder.getCurrentParagraph().isEndOfDocument());
      • getAddSpaceBetweenFarEastAndDigit/setAddSpaceBetweenFarEastAndDigit

        public boolean getAddSpaceBetweenFarEastAndDigit() / public void setAddSpaceBetweenFarEastAndDigit(boolean value)
        
        Gets or sets a flag indicating whether inter-character spacing is automatically adjusted between regions of numbers and regions of East Asian text in the current paragraph.

        Example:

        Shows how to insert a paragraph into the document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Font font = builder.getFont();
        font.setSize(16.0);
        font.setBold(true);
        font.setColor(Color.BLUE);
        font.setName("Arial");
        font.setUnderline(Underline.DASH);
        
        ParagraphFormat paragraphFormat = builder.getParagraphFormat();
        paragraphFormat.setFirstLineIndent(8.0);
        paragraphFormat.setAlignment(ParagraphAlignment.JUSTIFY);
        paragraphFormat.setAddSpaceBetweenFarEastAndAlpha(true);
        paragraphFormat.setAddSpaceBetweenFarEastAndDigit(true);
        paragraphFormat.setKeepTogether(true);
        
        // The "Writeln" method ends the paragraph after appending text
        // and then starts a new line, adding a new paragraph.
        builder.writeln("Hello world!");
        
        Assert.assertTrue(builder.getCurrentParagraph().isEndOfDocument());
      • getAlignment/setAlignment

        public int getAlignment() / public void setAlignment(int value)
        
        Gets or sets text alignment for the paragraph. The value of the property is ParagraphAlignment integer constant.

        Example:

        Shows how to insert a paragraph into the document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Font font = builder.getFont();
        font.setSize(16.0);
        font.setBold(true);
        font.setColor(Color.BLUE);
        font.setName("Arial");
        font.setUnderline(Underline.DASH);
        
        ParagraphFormat paragraphFormat = builder.getParagraphFormat();
        paragraphFormat.setFirstLineIndent(8.0);
        paragraphFormat.setAlignment(ParagraphAlignment.JUSTIFY);
        paragraphFormat.setAddSpaceBetweenFarEastAndAlpha(true);
        paragraphFormat.setAddSpaceBetweenFarEastAndDigit(true);
        paragraphFormat.setKeepTogether(true);
        
        // The "Writeln" method ends the paragraph after appending text
        // and then starts a new line, adding a new paragraph.
        builder.writeln("Hello world!");
        
        Assert.assertTrue(builder.getCurrentParagraph().isEndOfDocument());

        Example:

        Shows how to construct an Aspose.Words document by hand.
        Document doc = new Document();
        
        // A blank document contains one section, one body and one paragraph.
        // Call the "RemoveAllChildren" method to remove all those nodes,
        // and end up with a document node with no children.
        doc.removeAllChildren();
        
        // This document now has no composite child nodes that we can add content to.
        // If we wish to edit it, we will need to repopulate its node collection.
        // First, create a new section, and then append it as a child to the root document node.
        Section section = new Section(doc);
        doc.appendChild(section);
        
        // Set some page setup properties for the section.
        section.getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
        section.getPageSetup().setPaperSize(PaperSize.LETTER);
        
        // A section needs a body, which will contain and display all its contents
        // on the page between the section's header and footer.
        Body body = new Body(doc);
        section.appendChild(body);
        
        // Create a paragraph, set some formatting properties, and then append it as a child to the body.
        Paragraph para = new Paragraph(doc);
        
        para.getParagraphFormat().setStyleName("Heading 1");
        para.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        
        body.appendChild(para);
        
        // Finally, add some content to do the document. Create a run,
        // set its appearance and contents, and then append it as a child to the paragraph.
        Run run = new Run(doc);
        run.setText("Hello World!");
        run.getFont().setColor(Color.RED);
        para.appendChild(run);
        
        Assert.assertEquals("Hello World!", doc.getText().trim());
        
        doc.save(getArtifactsDir() + "Section.CreateManually.docx");
      • getBidi/setBidi

        public boolean getBidi() / public void setBidi(boolean value)
        
        Gets or sets whether this is a right-to-left paragraph.

        When true, the runs and other inline objects in this paragraph are laid out right to left.

        Example:

        Shows how to detect plaintext document text direction.
        // Create a "TxtLoadOptions" object, which we can pass to a document's constructor
        // to modify how we load a plaintext document.
        TxtLoadOptions loadOptions = new TxtLoadOptions();
        
        // Set the "DocumentDirection" property to "DocumentDirection.Auto" automatically detects
        // the direction of every paragraph of text that Aspose.Words loads from plaintext.
        // Each paragraph's "Bidi" property will store its direction.
        loadOptions.setDocumentDirection(DocumentDirection.AUTO);
        
        // Detect Hebrew text as right-to-left.
        Document doc = new Document(getMyDir() + "Hebrew text.txt", loadOptions);
        
        Assert.assertTrue(doc.getFirstSection().getBody().getFirstParagraph().getParagraphFormat().getBidi());
        
        // Detect English text as right-to-left.
        doc = new Document(getMyDir() + "English text.txt", loadOptions);
        
        Assert.assertFalse(doc.getFirstSection().getBody().getFirstParagraph().getParagraphFormat().getBidi());

        Example:

        Shows how to create right-to-left language-compatible lists with BIDIOUTLINE fields.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // The BIDIOUTLINE field numbers paragraphs like the AUTONUM/LISTNUM fields,
        // but is only visible when a right-to-left editing language is enabled, such as Hebrew or Arabic.
        // The following field will display ".1", the RTL equivalent of list number "1.".
        FieldBidiOutline field = (FieldBidiOutline) builder.insertField(FieldType.FIELD_BIDI_OUTLINE, true);
        builder.writeln("שלום");
        
        Assert.assertEquals(" BIDIOUTLINE ", field.getFieldCode());
        
        // Add two more BIDIOUTLINE fields, which will display ".2" and ".3".
        builder.insertField(FieldType.FIELD_BIDI_OUTLINE, true);
        builder.writeln("שלום");
        builder.insertField(FieldType.FIELD_BIDI_OUTLINE, true);
        builder.writeln("שלום");
        
        // Set the horizontal text alignment for every paragraph in the document to RTL.
        for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
            para.getParagraphFormat().setBidi(true);
        }
        
        // If we enable a right-to-left editing language in Microsoft Word, our fields will display numbers.
        // Otherwise, they will display "###".
        doc.save(getArtifactsDir() + "Field.BIDIOUTLINE.docx");
      • getBorders

        public BorderCollection getBorders()
        
        Gets collection of borders of the paragraph.

        Example:

        Shows how to insert a paragraph with a top border.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Border topBorder = builder.getParagraphFormat().getBorders().getByBorderType(BorderType.TOP);
        topBorder.setColor(Color.RED);
        topBorder.setLineWidth(4.0d);
        topBorder.setLineStyle(LineStyle.DASH_SMALL_GAP);
        
        builder.writeln("Text with a red top border.");
        
        doc.save(getArtifactsDir() + "Border.ParagraphTopBorder.docx");
      • getCharacterUnitFirstLineIndent/setCharacterUnitFirstLineIndent

        public double getCharacterUnitFirstLineIndent() / public void setCharacterUnitFirstLineIndent(double value)
        
        Gets or sets the value (in characters) for the first-line or hanging indent.

        Use positive values to set the first-line indent, and negative values to set the hanging indent.

      • getCharacterUnitLeftIndent/setCharacterUnitLeftIndent

        public double getCharacterUnitLeftIndent() / public void setCharacterUnitLeftIndent(double value)
        
        Gets or sets the left indent value (in characters) for the specified paragraphs.
      • getCharacterUnitRightIndent/setCharacterUnitRightIndent

        public double getCharacterUnitRightIndent() / public void setCharacterUnitRightIndent(double value)
        
        Gets or sets the right indent value (in characters) for the specified paragraphs.
      • getDropCapPosition/setDropCapPosition

        public int getDropCapPosition() / public void setDropCapPosition(int value)
        
        Gets or sets the position for a drop cap text. The value of the property is DropCapPosition integer constant.

        Example:

        Shows how to nest a list inside another list.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents.
        // We can create nested lists by increasing the indent level. 
        // We can begin and end a list by using a document builder's "ListFormat" property. 
        // Each paragraph that we add between a list's start and the end will become an item in the list.
        // Create an outline list for the headings.
        List outlineList = doc.getLists().add(ListTemplate.OUTLINE_NUMBERS);
        builder.getListFormat().setList(outlineList);
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
        builder.writeln("This is my Chapter 1");
        
        // Create a numbered list.
        List numberedList = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        builder.getListFormat().setList(numberedList);
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.NORMAL);
        builder.writeln("Numbered list item 1.");
        
        // Every paragraph that comprises a list will have this flag.
        Assert.assertTrue(builder.getCurrentParagraph().isListItem());
        Assert.assertTrue(builder.getParagraphFormat().isListItem());
        
        // Create a bulleted list.
        List bulletedList = doc.getLists().add(ListTemplate.BULLET_DEFAULT);
        builder.getListFormat().setList(bulletedList);
        builder.getParagraphFormat().setLeftIndent(72.0);
        builder.writeln("Bulleted list item 1.");
        builder.writeln("Bulleted list item 2.");
        builder.getParagraphFormat().clearFormatting();
        
        // Revert to the numbered list.
        builder.getListFormat().setList(numberedList);
        builder.writeln("Numbered list item 2.");
        builder.writeln("Numbered list item 3.");
        
        // Revert to the outline list.
        builder.getListFormat().setList(outlineList);
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
        builder.writeln("This is my Chapter 2");
        
        builder.getParagraphFormat().clearFormatting();
        
        builder.getDocument().save(getArtifactsDir() + "Lists.NestedLists.docx");
      • getFarEastLineBreakControl/setFarEastLineBreakControl

        public boolean getFarEastLineBreakControl() / public void setFarEastLineBreakControl(boolean value)
        
        Gets or sets a flag indicating whether East Asian line-breaking rules are applied to the current paragraph.
      • getFirstLineIndent/setFirstLineIndent

        public double getFirstLineIndent() / public void setFirstLineIndent(double value)
        
        Gets or sets the value (in points) for a first line or hanging indent.

        Use positive values to set the first-line indent, and negative values to set the hanging indent.

        Example:

        Shows how to insert a paragraph into the document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Font font = builder.getFont();
        font.setSize(16.0);
        font.setBold(true);
        font.setColor(Color.BLUE);
        font.setName("Arial");
        font.setUnderline(Underline.DASH);
        
        ParagraphFormat paragraphFormat = builder.getParagraphFormat();
        paragraphFormat.setFirstLineIndent(8.0);
        paragraphFormat.setAlignment(ParagraphAlignment.JUSTIFY);
        paragraphFormat.setAddSpaceBetweenFarEastAndAlpha(true);
        paragraphFormat.setAddSpaceBetweenFarEastAndDigit(true);
        paragraphFormat.setKeepTogether(true);
        
        // The "Writeln" method ends the paragraph after appending text
        // and then starts a new line, adding a new paragraph.
        builder.writeln("Hello world!");
        
        Assert.assertTrue(builder.getCurrentParagraph().isEndOfDocument());
      • getHangingPunctuation/setHangingPunctuation

        public boolean getHangingPunctuation() / public void setHangingPunctuation(boolean value)
        
        Gets or sets a flag indicating whether hanging punctuation is enabled for the current paragraph.
      • isHeading

        public boolean isHeading()
        
        True when the paragraph style is one of the built-in Heading styles.

        Example:

        Shows how to limit the headings' level that will appear in the outline of a saved PDF document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert headings that can serve as TOC entries of levels 1, 2, and then 3.
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
        
        Assert.assertTrue(builder.getParagraphFormat().isHeading());
        
        builder.writeln("Heading 1");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
        
        builder.writeln("Heading 1.1");
        builder.writeln("Heading 1.2");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_3);
        
        builder.writeln("Heading 1.2.1");
        builder.writeln("Heading 1.2.2");
        
        // Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
        // to modify how that method converts the document to .PDF.
        PdfSaveOptions saveOptions = new PdfSaveOptions();
        saveOptions.setSaveFormat(SaveFormat.PDF);
        
        // The output PDF document will contain an outline, which is a table of contents that lists headings in the document body.
        // Clicking on an entry in this outline will take us to the location of its respective heading.
        // Set the "HeadingsOutlineLevels" property to "2" to exclude all headings whose levels are above 2 from the outline.
        // The last two headings we have inserted above will not appear.
        saveOptions.getOutlineOptions().setHeadingsOutlineLevels(2);
        
        doc.save(getArtifactsDir() + "PdfSaveOptions.HeadingsOutlineLevels.pdf", saveOptions);
      • isListItem

        public boolean isListItem()
        
        True when the paragraph is an item in a bulleted or numbered list.

        Example:

        Shows how to nest a list inside another list.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents.
        // We can create nested lists by increasing the indent level. 
        // We can begin and end a list by using a document builder's "ListFormat" property. 
        // Each paragraph that we add between a list's start and the end will become an item in the list.
        // Create an outline list for the headings.
        List outlineList = doc.getLists().add(ListTemplate.OUTLINE_NUMBERS);
        builder.getListFormat().setList(outlineList);
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
        builder.writeln("This is my Chapter 1");
        
        // Create a numbered list.
        List numberedList = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        builder.getListFormat().setList(numberedList);
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.NORMAL);
        builder.writeln("Numbered list item 1.");
        
        // Every paragraph that comprises a list will have this flag.
        Assert.assertTrue(builder.getCurrentParagraph().isListItem());
        Assert.assertTrue(builder.getParagraphFormat().isListItem());
        
        // Create a bulleted list.
        List bulletedList = doc.getLists().add(ListTemplate.BULLET_DEFAULT);
        builder.getListFormat().setList(bulletedList);
        builder.getParagraphFormat().setLeftIndent(72.0);
        builder.writeln("Bulleted list item 1.");
        builder.writeln("Bulleted list item 2.");
        builder.getParagraphFormat().clearFormatting();
        
        // Revert to the numbered list.
        builder.getListFormat().setList(numberedList);
        builder.writeln("Numbered list item 2.");
        builder.writeln("Numbered list item 3.");
        
        // Revert to the outline list.
        builder.getListFormat().setList(outlineList);
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
        builder.writeln("This is my Chapter 2");
        
        builder.getParagraphFormat().clearFormatting();
        
        builder.getDocument().save(getArtifactsDir() + "Lists.NestedLists.docx");
      • getKeepTogether/setKeepTogether

        public boolean getKeepTogether() / public void setKeepTogether(boolean value)
        
        True if all lines in the paragraph are to remain on the same page.

        Example:

        Shows how to insert a paragraph into the document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Font font = builder.getFont();
        font.setSize(16.0);
        font.setBold(true);
        font.setColor(Color.BLUE);
        font.setName("Arial");
        font.setUnderline(Underline.DASH);
        
        ParagraphFormat paragraphFormat = builder.getParagraphFormat();
        paragraphFormat.setFirstLineIndent(8.0);
        paragraphFormat.setAlignment(ParagraphAlignment.JUSTIFY);
        paragraphFormat.setAddSpaceBetweenFarEastAndAlpha(true);
        paragraphFormat.setAddSpaceBetweenFarEastAndDigit(true);
        paragraphFormat.setKeepTogether(true);
        
        // The "Writeln" method ends the paragraph after appending text
        // and then starts a new line, adding a new paragraph.
        builder.writeln("Hello world!");
        
        Assert.assertTrue(builder.getCurrentParagraph().isEndOfDocument());
      • getKeepWithNext/setKeepWithNext

        public boolean getKeepWithNext() / public void setKeepWithNext(boolean value)
        
        True if the paragraph is to remains on the same page as the paragraph that follows it.

        Example:

        Shows how to set a table to stay together on the same page.
        Document doc = new Document(getMyDir() + "Table spanning two pages.docx");
        Table table = doc.getFirstSection().getBody().getTables().get(0);
        
        // Enabling KeepWithNext for every paragraph in the table except for the
        // last ones in the last row will prevent the table from splitting across multiple pages.
        for (Cell cell : (Iterable<Cell>) table.getChildNodes(NodeType.CELL, true))
            for (Paragraph para : cell.getParagraphs()) {
                Assert.assertTrue(para.isInCell());
        
                if (!(cell.getParentRow().isLastRow() && para.isEndOfCell()))
                    para.getParagraphFormat().setKeepWithNext(true);
            }
        
        doc.save(getArtifactsDir() + "Table.KeepTableTogether.docx");
      • getLeftIndent/setLeftIndent

        public double getLeftIndent() / public void setLeftIndent(double value)
        
        Gets or sets the value (in points) that represents the left indent for paragraph.

        Example:

        Shows how to configure paragraph formatting to create off-center text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Center all text that the document builder writes, and set up indents.
        // The indent configuration below will create a body of text that will sit asymmetrically on the page.
        // The "center" that we align the text to will be the middle of the body of text, not the middle of the page.
        ParagraphFormat paragraphFormat = builder.getParagraphFormat();
        paragraphFormat.setAlignment(ParagraphAlignment.CENTER);
        paragraphFormat.setLeftIndent(100.0);
        paragraphFormat.setRightIndent(50.0);
        paragraphFormat.setSpaceAfter(25.0);
        
        builder.writeln(
                "This paragraph demonstrates how left and right indentation affects word wrapping.");
        builder.writeln(
                "The space between the above paragraph and this one depends on the DocumentBuilder's paragraph format.");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.SetParagraphFormatting.docx");
      • getLineSpacing/setLineSpacing

        public double getLineSpacing() / public void setLineSpacing(double value)
        
        Gets or sets the line spacing (in points) for the paragraph.

        When LineSpacingRule property is set to AtLeast, the line spacing can be greater than or equal to, but never less than the specified LineSpacing value.

        When LineSpacingRule property is set to Exactly, the line spacing never changes from the specified LineSpacing value, even if a larger font is used within the paragraph.

      • getLineSpacingRule/setLineSpacingRule

        public int getLineSpacingRule() / public void setLineSpacingRule(int value)
        
        Gets or sets the line spacing for the paragraph. The value of the property is LineSpacingRule integer constant.
      • getLinesToDrop/setLinesToDrop

        public int getLinesToDrop() / public void setLinesToDrop(int value)
        
        Gets or sets the number of lines of the paragraph text used to calculate the drop cap height.
      • getLineUnitAfter/setLineUnitAfter

        public double getLineUnitAfter() / public void setLineUnitAfter(double value)
        
        Gets or sets the amount of spacing (in gridlines) after the paragraphs.
      • getLineUnitBefore/setLineUnitBefore

        public double getLineUnitBefore() / public void setLineUnitBefore(double value)
        
        Gets or sets the amount of spacing (in gridlines) before the paragraphs.
      • getNoSpaceBetweenParagraphsOfSameStyle/setNoSpaceBetweenParagraphsOfSameStyle

        public boolean getNoSpaceBetweenParagraphsOfSameStyle() / public void setNoSpaceBetweenParagraphsOfSameStyle(boolean value)
        
        When true, SpaceBefore and SpaceAfter will be ignored between the paragraphs of the same style.

        This setting only takes affect when applied to a paragraph style. If applied to a paragraph directly, it has no effect.

      • getOutlineLevel/setOutlineLevel

        public int getOutlineLevel() / public void setOutlineLevel(int value)
        
        Specifies the outline level of the paragraph in the document. The value of the property is OutlineLevel integer constant.
      • getPageBreakBefore/setPageBreakBefore

        public boolean getPageBreakBefore() / public void setPageBreakBefore(boolean value)
        
        True if a page break is forced before the paragraph.
      • getRightIndent/setRightIndent

        public double getRightIndent() / public void setRightIndent(double value)
        
        Gets or sets the value (in points) that represents the right indent for paragraph.

        Example:

        Shows how to configure paragraph formatting to create off-center text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Center all text that the document builder writes, and set up indents.
        // The indent configuration below will create a body of text that will sit asymmetrically on the page.
        // The "center" that we align the text to will be the middle of the body of text, not the middle of the page.
        ParagraphFormat paragraphFormat = builder.getParagraphFormat();
        paragraphFormat.setAlignment(ParagraphAlignment.CENTER);
        paragraphFormat.setLeftIndent(100.0);
        paragraphFormat.setRightIndent(50.0);
        paragraphFormat.setSpaceAfter(25.0);
        
        builder.writeln(
                "This paragraph demonstrates how left and right indentation affects word wrapping.");
        builder.writeln(
                "The space between the above paragraph and this one depends on the DocumentBuilder's paragraph format.");
        
        doc.save(getArtifactsDir() + "DocumentBuilder.SetParagraphFormatting.docx");
      • getShading

        public Shading getShading()
        
        Returns a Shading object that refers to the shading formatting for the paragraph.

        Example:

        Shows how to decorate text with borders and shading.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        BorderCollection borders = builder.getParagraphFormat().getBorders();
        borders.setDistanceFromText(20.0);
        borders.getByBorderType(BorderType.LEFT).setLineStyle(LineStyle.DOUBLE);
        borders.getByBorderType(BorderType.RIGHT).setLineStyle(LineStyle.DOUBLE);
        borders.getByBorderType(BorderType.TOP).setLineStyle(LineStyle.DOUBLE);
        borders.getByBorderType(BorderType.BOTTOM).setLineStyle(LineStyle.DOUBLE);
        
        Shading shading = builder.getParagraphFormat().getShading();
        shading.setTexture(TextureIndex.TEXTURE_DIAGONAL_CROSS);
        shading.setBackgroundPatternColor(new Color(240, 128, 128));  // Light Coral
        shading.setForegroundPatternColor(new Color(255, 160, 122));  // Light Salmon
        
        builder.write("This paragraph is formatted with a double border and shading.");
        doc.save(getArtifactsDir() + "DocumentBuilder.ApplyBordersAndShading.docx");
      • getSnapToGrid/setSnapToGrid

        public boolean getSnapToGrid() / public void setSnapToGrid(boolean value)
        
        Specifies whether the current paragraph should use the document grid lines per page settings when laying out the contents in the paragraph.

        Example:

        Shows how to specify a limit for the number of lines that each page may have.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Enable pitching, and then use it to set the number of lines per page in this section.
        // A large enough font size will push some lines down onto the next page to avoid overlapping characters.
        builder.getPageSetup().setLayoutMode(SectionLayoutMode.LINE_GRID);
        builder.getPageSetup().setLinesPerPage(15);
        
        builder.getParagraphFormat().setSnapToGrid(true);
        
        for (int i = 0; i < 30; i++)
            builder.write("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ");
        
        doc.save(getArtifactsDir() + "PageSetup.LinesPerPage.docx");
      • getSpaceAfter/setSpaceAfter

        public double getSpaceAfter() / public void setSpaceAfter(double value)
        
        Gets or sets the amount of spacing (in points) after the paragraph.

        Has no effect when SpaceAfterAuto is true.

        Valid values ​​range from 0 to 1584 inclusive.

      • getSpaceAfterAuto/setSpaceAfterAuto

        public boolean getSpaceAfterAuto() / public void setSpaceAfterAuto(boolean value)
        
        True if the amount of spacing after the paragraph is set automatically.

        When set to true, overrides the effect of SpaceAfter.

        When you set paragraph Space Before and Space After to Auto, Microsoft Word adds 14 points spacing between paragraphs automatically according to the following rules:

        • Normally, spacing is added after all paragraphs.
        • In a bulleted or numbered list, spacing is added only after the last item in the list. Spacing is not added between the list items.
        • In a nested bulleted or numbered list spacing is not added.
        • Spacing is normally added after a table.
        • Spacing is not added after a table if it is the last block in a table cell.
        • Spacing is not added after the last paragraph in a table cell.
      • getSpaceBefore/setSpaceBefore

        public double getSpaceBefore() / public void setSpaceBefore(double value)
        
        Gets or sets the amount of spacing (in points) before the paragraph.

        Has no effect when SpaceBeforeAuto is true.

        Valid values range from 0 to 1584 inclusive.

      • getSpaceBeforeAuto/setSpaceBeforeAuto

        public boolean getSpaceBeforeAuto() / public void setSpaceBeforeAuto(boolean value)
        
        True if the amount of spacing before the paragraph is set automatically.

        When set to true, overrides the effect of SpaceBefore.

        When you set paragraph Space Before and Space After to Auto, Microsoft Word adds 14 points spacing between paragraphs automatically according to the following rules:

        • Normally, spacing is added after all paragraphs.
        • In a bulleted or numbered list, spacing is added only after the last item in the list. Spacing is not added between the list items.
        • In a nested bulleted or numbered list spacing is not added.
        • Spacing is normally added after a table.
        • Spacing is not added after a table if it is the last block in a table cell.
        • Spacing is not added after the last paragraph in a table cell.
      • getStyle/setStyle

        public Style getStyle() / public void setStyle(Style value)
        
        Gets or sets the paragraph style applied to this formatting.

        Example:

        Shows how to create and use a paragraph style with list formatting.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a custom paragraph style.
        Style style = doc.getStyles().add(StyleType.PARAGRAPH, "MyStyle1");
        style.getFont().setSize(24.0);
        style.getFont().setName("Verdana");
        style.getParagraphFormat().setSpaceAfter(12.0);
        
        // Create a list and make sure the paragraphs that use this style will use this list.
        style.getListFormat().setList(doc.getLists().add(ListTemplate.BULLET_DEFAULT));
        style.getListFormat().setListLevelNumber(0);
        
        // Apply the paragraph style to the document builder's current paragraph, and then add some text.
        builder.getParagraphFormat().setStyle(style);
        builder.writeln("Hello World: MyStyle1, bulleted list.");
        
        // Change the document builder's style to one that has no list formatting and write another paragraph.
        builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
        builder.writeln("Hello World: Normal.");
        
        builder.getDocument().save(getArtifactsDir() + "Styles.ParagraphStyleBulletedList.docx");
      • getStyleIdentifier/setStyleIdentifier

        public int getStyleIdentifier() / public void setStyleIdentifier(int value)
        
        Gets or sets the locale independent style identifier of the paragraph style applied to this formatting. The value of the property is StyleIdentifier integer constant.

        Example:

        Shows how to insert a Table of contents (TOC) into a document using heading styles as entries.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a table of contents for the first page of the document.
        // Configure the table to pick up paragraphs with headings of levels 1 to 3.
        // Also, set its entries to be hyperlinks that will take us
        // to the location of the heading when left-clicked in Microsoft Word.
        builder.insertTableOfContents("\\o \"1-3\" \\h \\z \\u");
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // Populate the table of contents by adding paragraphs with heading styles.
        // Each such heading with a level between 1 and 3 will create an entry in the table.
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
        builder.writeln("Heading 1");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
        builder.writeln("Heading 1.1");
        builder.writeln("Heading 1.2");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
        builder.writeln("Heading 2");
        builder.writeln("Heading 3");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
        builder.writeln("Heading 3.1");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_3);
        builder.writeln("Heading 3.1.1");
        builder.writeln("Heading 3.1.2");
        builder.writeln("Heading 3.1.3");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_4);
        builder.writeln("Heading 3.1.3.1");
        builder.writeln("Heading 3.1.3.2");
        
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
        builder.writeln("Heading 3.2");
        builder.writeln("Heading 3.3");
        
        // A table of contents is a field of a type that needs to be updated to show an up-to-date result.
        doc.updateFields();
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertToc.docx");
      • getStyleName/setStyleName

        public java.lang.String getStyleName() / public void setStyleName(java.lang.String value)
        
        Gets or sets the name of the paragraph style applied to this formatting.

        Example:

        Shows how to construct an Aspose.Words document by hand.
        Document doc = new Document();
        
        // A blank document contains one section, one body and one paragraph.
        // Call the "RemoveAllChildren" method to remove all those nodes,
        // and end up with a document node with no children.
        doc.removeAllChildren();
        
        // This document now has no composite child nodes that we can add content to.
        // If we wish to edit it, we will need to repopulate its node collection.
        // First, create a new section, and then append it as a child to the root document node.
        Section section = new Section(doc);
        doc.appendChild(section);
        
        // Set some page setup properties for the section.
        section.getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
        section.getPageSetup().setPaperSize(PaperSize.LETTER);
        
        // A section needs a body, which will contain and display all its contents
        // on the page between the section's header and footer.
        Body body = new Body(doc);
        section.appendChild(body);
        
        // Create a paragraph, set some formatting properties, and then append it as a child to the body.
        Paragraph para = new Paragraph(doc);
        
        para.getParagraphFormat().setStyleName("Heading 1");
        para.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
        
        body.appendChild(para);
        
        // Finally, add some content to do the document. Create a run,
        // set its appearance and contents, and then append it as a child to the paragraph.
        Run run = new Run(doc);
        run.setText("Hello World!");
        run.getFont().setColor(Color.RED);
        para.appendChild(run);
        
        Assert.assertEquals("Hello World!", doc.getText().trim());
        
        doc.save(getArtifactsDir() + "Section.CreateManually.docx");
      • getSuppressAutoHyphens/setSuppressAutoHyphens

        public boolean getSuppressAutoHyphens() / public void setSuppressAutoHyphens(boolean value)
        
        Specifies whether the current paragraph should be exempted from any hyphenation which is applied in the document settings.
      • getSuppressLineNumbers/setSuppressLineNumbers

        public boolean getSuppressLineNumbers() / public void setSuppressLineNumbers(boolean value)
        
        Specifies whether the current paragraph's lines should be exempted from line numbering which is applied in the parent section.

        Example:

        Shows how to enable line numbering for a section.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // We can use the section's PageSetup object to display numbers to the left of the section's text lines.
        // This is the same behavior as a List object,
        // but it covers the entire section and does not modify the text in any way.
        // Our section will restart the numbering on each new page from 1 and display the number,
        // if it is a multiple of 3, at 50pt to the left of the line.
        PageSetup pageSetup = builder.getPageSetup();
        pageSetup.setLineStartingNumber(1);
        pageSetup.setLineNumberCountBy(3);
        pageSetup.setLineNumberRestartMode(LineNumberRestartMode.RESTART_PAGE);
        pageSetup.setLineNumberDistanceFromText(50.0d);
        
        for (int i = 1; i <= 25; i++)
            builder.writeln(MessageFormat.format("Line {0}.", i));
        
        // The line counter will skip any paragraph with the "SuppressLineNumbers" flag set to "true".
        // This paragraph is on the 15th line, which is a multiple of 3, and thus would normally display a line number.
        // The section's line counter will also ignore this line, treat the next line as the 15th,
        // and continue the count from that point onward.
        doc.getFirstSection().getBody().getParagraphs().get(14).getParagraphFormat().setSuppressLineNumbers(true);
        
        doc.save(getArtifactsDir() + "PageSetup.LineNumbers.docx");
      • getTabStops

        public TabStopCollection getTabStops()
        
        Gets the collection of custom tab stops defined for this object.

        Example:

        Shows how to modify the position of the right tab stop in TOC related paragraphs.
        Document doc = new Document(getMyDir() + "Table of contents.docx");
        
        // Iterate through all paragraphs with TOC result-based styles; this is any style between TOC and TOC9.
        for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
            if (para.getParagraphFormat().getStyle().getStyleIdentifier() >= StyleIdentifier.TOC_1
                    && para.getParagraphFormat().getStyle().getStyleIdentifier() <= StyleIdentifier.TOC_9) {
                // Get the first tab used in this paragraph, this should be the tab used to align the page numbers.
                TabStop tab = para.getParagraphFormat().getTabStops().get(0);
        
                // Replace the first default tab, stop with a custom tab stop.
                para.getParagraphFormat().getTabStops().removeByPosition(tab.getPosition());
                para.getParagraphFormat().getTabStops().add(tab.getPosition() - 50.0, tab.getAlignment(), tab.getLeader());
            }
        }
        
        doc.save(getArtifactsDir() + "Styles.ChangeTocsTabStops.docx");
      • getWidowControl/setWidowControl

        public boolean getWidowControl() / public void setWidowControl(boolean value)
        
        True if the first and last lines in the paragraph are to remain on the same page as the rest of the paragraph.
      • getWordWrap/setWordWrap

        public boolean getWordWrap() / public void setWordWrap(boolean value)
        
        If this property is false, Latin text in the middle of a word can be wrapped for the current paragraph. Otherwise Latin text is wrapped by whole words.
    • Method Detail

      • clearFormatting

        public void clearFormatting()
        Resets to default paragraph formatting. Default paragraph formatting is Normal style, left aligned, no indentation, no spacing, no borders and no shading.

        Example:

        Shows how to nest a list inside another list.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents.
        // We can create nested lists by increasing the indent level. 
        // We can begin and end a list by using a document builder's "ListFormat" property. 
        // Each paragraph that we add between a list's start and the end will become an item in the list.
        // Create an outline list for the headings.
        List outlineList = doc.getLists().add(ListTemplate.OUTLINE_NUMBERS);
        builder.getListFormat().setList(outlineList);
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
        builder.writeln("This is my Chapter 1");
        
        // Create a numbered list.
        List numberedList = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        builder.getListFormat().setList(numberedList);
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.NORMAL);
        builder.writeln("Numbered list item 1.");
        
        // Every paragraph that comprises a list will have this flag.
        Assert.assertTrue(builder.getCurrentParagraph().isListItem());
        Assert.assertTrue(builder.getParagraphFormat().isListItem());
        
        // Create a bulleted list.
        List bulletedList = doc.getLists().add(ListTemplate.BULLET_DEFAULT);
        builder.getListFormat().setList(bulletedList);
        builder.getParagraphFormat().setLeftIndent(72.0);
        builder.writeln("Bulleted list item 1.");
        builder.writeln("Bulleted list item 2.");
        builder.getParagraphFormat().clearFormatting();
        
        // Revert to the numbered list.
        builder.getListFormat().setList(numberedList);
        builder.writeln("Numbered list item 2.");
        builder.writeln("Numbered list item 3.");
        
        // Revert to the outline list.
        builder.getListFormat().setList(outlineList);
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
        builder.writeln("This is my Chapter 2");
        
        builder.getParagraphFormat().clearFormatting();
        
        builder.getDocument().save(getArtifactsDir() + "Lists.NestedLists.docx");