java.lang.Object
com.aspose.words.ParagraphFormat
public class ParagraphFormat
- extends java.lang.Object
Represents all the formatting for a paragraph.
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");
Property Getters/Setters Detail |
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:
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");
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.
getKeepTogether/setKeepTogether | |
public boolean getKeepTogether() / public void setKeepTogether(boolean value)
|
-
True if all lines in the paragraph are to remain on the same page.
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.
getPageBreakBefore/setPageBreakBefore | |
public boolean getPageBreakBefore() / public void setPageBreakBefore(boolean value)
|
-
True if a page break is forced before the paragraph.
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.
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.
getBidi/setBidi | |
public boolean getBidi() / public void setBidi(boolean value)
|
-
Gets or sets whether this is a rigt-to-left paragraph.
When true, the runs and other inline objects in this paragraph
are laid out right to left.
getLeftIndent/setLeftIndent | |
public double getLeftIndent() / public void setLeftIndent(double value)
|
-
Gets or sets the value (in points) that represents the left indent for 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.
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 a positive value to set a first-line indent, and use a negative value to set a hanging indent.
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.
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.
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.
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.
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 propert is set to Exactly, the line spacing never changes from
the specified LineSpacing value, even if a larger font is used within the paragraph.
isHeading | |
public boolean isHeading()
|
-
True when the paragraph style is one of the built-in Heading styles.
isListItem | |
public boolean isListItem()
|
-
True when the paragraph is an item in a bulleted or numbered list.
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.
getShading | |
public Shading getShading()
|
-
Returns a Shading object that refers to the shading formatting for the paragraph.
-
Gets collection of borders of the paragraph.
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 paragraph style and specify some formatting for it.
Style style = doc.getStyles().add(StyleType.PARAGRAPH, "MyStyle1");
style.getFont().setSize(24);
style.getFont().setName("Verdana");
style.getParagraphFormat().setSpaceAfter(12);
// 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 current paragraph in the document and add some text.
builder.getParagraphFormat().setStyle(style);
builder.writeln("Hello World: MyStyle1, bulleted.");
// Change to a paragraph style that has no list formatting.
builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
builder.writeln("Hello World: Normal.");
builder.getDocument().save(getMyDir() + "Lists.ParagraphStyleBulleted Out.doc");
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:
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");
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:
Demonstrates how to insert a TOC into a document using heading styles as entries.
DocumentBuilder builder = new DocumentBuilder();
// Insrt a table of contents at the beginning of the document.
builder.insertTableOfContents("\\o \"1-3\" \\h \\z \\u");
// Build a document with complex structure by applying different heading styles thus creating TOC entries.
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_2);
builder.writeln("Heading 3.2");
builder.writeln("Heading 3.3");
builder.getDocument().save(getMyDir() + "DocumentBuilder.InsertToc Out.doc");
// Don't forget to update fields of the document by pressing F9 in Microsoft Word to see the TOC.
-
Gets the collection of custom tab stops defined for this object.
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.
getDirectBorderAttr | |
public java.lang.Object getDirectBorderAttr(int key)
throws java.lang.Exception |
- Reserved for internal use.
fetchInheritedBorderAttr | |
public java.lang.Object fetchInheritedBorderAttr(int key)
throws java.lang.Exception |
- Reserved for internal use.
setBorderAttr | |
public void setBorderAttr(int key, java.lang.Object value) |
- Reserved for internal use.
fetchInheritedShadingAttr | |
public java.lang.Object fetchInheritedShadingAttr(int key)
throws java.lang.Exception |
- Reserved for internal use.
See Also:
Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
Aspose.Words Support Forum - our preferred method of support.