Aspose::Words::ParagraphFormat Class Reference

Detailed Description

Represents all the formatting for a paragraph.

Examples

Shows how to construct an Aspose.Words document by hand.

auto doc = MakeObject<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.
auto section = MakeObject<Section>(doc);
doc->AppendChild(section);
// Set some page setup properties for the section.
section->get_PageSetup()->set_SectionStart(SectionStart::NewPage);
section->get_PageSetup()->set_PaperSize(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.
auto body = MakeObject<Body>(doc);
section->AppendChild(body);
// Create a paragraph, set some formatting properties, and then append it as a child to the body.
auto para = MakeObject<Paragraph>(doc);
para->get_ParagraphFormat()->set_StyleName(u"Heading 1");
para->get_ParagraphFormat()->set_Alignment(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.
auto run = MakeObject<Run>(doc);
run->set_Text(u"Hello World!");
run->get_Font()->set_Color(System::Drawing::Color::get_Red());
para->AppendChild(run);
ASSERT_EQ(u"Hello World!", doc->GetText().Trim());
doc->Save(ArtifactsDir + u"Section.CreateManually.docx");

#include <Aspose.Words.Cpp/ParagraphFormat.h>

+ Inheritance diagram for Aspose::Words::ParagraphFormat:

Public Member Functions

void ClearFormatting ()
 Resets to default paragraph formatting. More...
 
bool get_AddSpaceBetweenFarEastAndAlpha ()
 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. More...
 
bool get_AddSpaceBetweenFarEastAndDigit ()
 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. More...
 
ParagraphAlignment get_Alignment ()
 Gets or sets text alignment for the paragraph. More...
 
bool get_Bidi ()
 Gets or sets whether this is a right-to-left paragraph. More...
 
SharedPtr< BorderCollectionget_Borders ()
 Gets collection of borders of the paragraph. More...
 
double get_CharacterUnitFirstLineIndent ()
 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. More...
 
double get_CharacterUnitLeftIndent ()
 Gets or sets the left indent value (in characters) for the specified paragraphs. More...
 
double get_CharacterUnitRightIndent ()
 Gets or sets the right indent value (in characters) for the specified paragraphs. More...
 
DropCapPosition get_DropCapPosition ()
 Gets or sets the position for a drop cap text. More...
 
bool get_FarEastLineBreakControl ()
 Gets or sets a flag indicating whether East Asian line-breaking rules are applied to the current paragraph. More...
 
double get_FirstLineIndent ()
 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. More...
 
bool get_HangingPunctuation ()
 Gets or sets a flag indicating whether hanging punctuation is enabled for the current paragraph. More...
 
bool get_IsHeading ()
 True when the paragraph style is one of the built-in Heading styles. More...
 
bool get_IsListItem ()
 True when the paragraph is an item in a bulleted or numbered list. More...
 
bool get_KeepTogether ()
 True if all lines in the paragraph are to remain on the same page. More...
 
bool get_KeepWithNext ()
 True if the paragraph is to remains on the same page as the paragraph that follows it. More...
 
double get_LeftIndent ()
 Gets or sets the value (in points) that represents the left indent for paragraph. More...
 
double get_LineSpacing ()
 Gets or sets the line spacing (in points) for the paragraph. More...
 
LineSpacingRule get_LineSpacingRule ()
 Gets or sets the line spacing for the paragraph. More...
 
int32_t get_LinesToDrop ()
 Gets or sets the number of lines of the paragraph text used to calculate the drop cap height. More...
 
double get_LineUnitAfter ()
 Gets or sets the amount of spacing (in gridlines) after the paragraphs. More...
 
double get_LineUnitBefore ()
 Gets or sets the amount of spacing (in gridlines) before the paragraphs. More...
 
bool get_NoSpaceBetweenParagraphsOfSameStyle ()
 When true, SpaceBefore and SpaceAfter will be ignored between the paragraphs of the same style. More...
 
OutlineLevel get_OutlineLevel ()
 Specifies the outline level of the paragraph in the document. More...
 
bool get_PageBreakBefore ()
 True if a page break is forced before the paragraph. More...
 
double get_RightIndent ()
 Gets or sets the value (in points) that represents the right indent for paragraph. More...
 
SharedPtr< Shadingget_Shading ()
 Returns a Shading object that refers to the shading formatting for the paragraph. More...
 
bool get_SnapToGrid ()
 Specifies whether the current paragraph should use the document grid lines per page settings when laying out the contents in the paragraph. More...
 
double get_SpaceAfter ()
 Gets or sets the amount of spacing (in points) after the paragraph. More...
 
bool get_SpaceAfterAuto ()
 True if the amount of spacing after the paragraph is set automatically. More...
 
double get_SpaceBefore ()
 Gets or sets the amount of spacing (in points) before the paragraph. More...
 
bool get_SpaceBeforeAuto ()
 True if the amount of spacing before the paragraph is set automatically. More...
 
SharedPtr< Styleget_Style ()
 Gets or sets the paragraph style applied to this formatting. More...
 
StyleIdentifier get_StyleIdentifier ()
 Gets or sets the locale independent style identifier of the paragraph style applied to this formatting. More...
 
String get_StyleName ()
 Gets or sets the name of the paragraph style applied to this formatting. More...
 
bool get_SuppressAutoHyphens ()
 Specifies whether the current paragraph should be exempted from any hyphenation which is applied in the document settings. More...
 
bool get_SuppressLineNumbers ()
 Specifies whether the current paragraph's lines should be exempted from line numbering which is applied in the parent section. More...
 
SharedPtr< TabStopCollectionget_TabStops ()
 Gets the collection of custom tab stops defined for this object. More...
 
bool get_WidowControl ()
 True if the first and last lines in the paragraph are to remain on the same page as the rest of the paragraph. More...
 
bool get_WordWrap ()
 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. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_AddSpaceBetweenFarEastAndAlpha (bool value)
 Setter for get_AddSpaceBetweenFarEastAndAlpha. More...
 
void set_AddSpaceBetweenFarEastAndDigit (bool value)
 Setter for get_AddSpaceBetweenFarEastAndDigit. More...
 
void set_Alignment (ParagraphAlignment value)
 Setter for get_Alignment. More...
 
void set_Bidi (bool value)
 Setter for get_Bidi. More...
 
void set_CharacterUnitFirstLineIndent (double value)
 Setter for get_CharacterUnitFirstLineIndent. More...
 
void set_CharacterUnitLeftIndent (double value)
 Setter for get_CharacterUnitLeftIndent. More...
 
void set_CharacterUnitRightIndent (double value)
 Setter for get_CharacterUnitRightIndent. More...
 
void set_DropCapPosition (DropCapPosition value)
 Setter for get_DropCapPosition. More...
 
void set_FarEastLineBreakControl (bool value)
 Setter for get_FarEastLineBreakControl. More...
 
void set_FirstLineIndent (double value)
 Setter for get_FirstLineIndent. More...
 
void set_HangingPunctuation (bool value)
 Setter for get_HangingPunctuation. More...
 
void set_KeepTogether (bool value)
 Setter for get_KeepTogether. More...
 
void set_KeepWithNext (bool value)
 Setter for get_KeepWithNext. More...
 
void set_LeftIndent (double value)
 Setter for get_LeftIndent. More...
 
void set_LineSpacing (double value)
 Setter for get_LineSpacing. More...
 
void set_LineSpacingRule (LineSpacingRule value)
 Setter for get_LineSpacingRule. More...
 
void set_LinesToDrop (int32_t value)
 Setter for get_LinesToDrop. More...
 
void set_LineUnitAfter (double value)
 Setter for get_LineUnitAfter. More...
 
void set_LineUnitBefore (double value)
 Setter for get_LineUnitBefore. More...
 
void set_NoSpaceBetweenParagraphsOfSameStyle (bool value)
 Setter for get_NoSpaceBetweenParagraphsOfSameStyle. More...
 
void set_OutlineLevel (OutlineLevel value)
 Setter for get_OutlineLevel. More...
 
void set_PageBreakBefore (bool value)
 Setter for get_PageBreakBefore. More...
 
void set_RightIndent (double value)
 Setter for get_RightIndent. More...
 
void set_SnapToGrid (bool value)
 Setter for get_SnapToGrid. More...
 
void set_SpaceAfter (double value)
 Setter for get_SpaceAfter. More...
 
void set_SpaceAfterAuto (bool value)
 Setter for get_SpaceAfterAuto. More...
 
void set_SpaceBefore (double value)
 Setter for get_SpaceBefore. More...
 
void set_SpaceBeforeAuto (bool value)
 Setter for get_SpaceBeforeAuto. More...
 
void set_Style (const SharedPtr< Style > &value)
 Setter for get_Style. More...
 
void set_StyleIdentifier (StyleIdentifier value)
 Setter for get_StyleIdentifier. More...
 
void set_StyleName (const String &value)
 Setter for get_StyleName. More...
 
void set_SuppressAutoHyphens (bool value)
 Setter for get_SuppressAutoHyphens. More...
 
void set_SuppressLineNumbers (bool value)
 Setter for get_SuppressLineNumbers. More...
 
void set_WidowControl (bool value)
 Setter for get_WidowControl. More...
 
void set_WordWrap (bool value)
 Setter for get_WordWrap. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ ClearFormatting()

void Aspose::Words::ParagraphFormat::ClearFormatting ( )

Resets to default paragraph formatting.

Examples

Shows how to nest a list inside another list.

auto doc = MakeObject<Document>();
auto builder = MakeObject<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.
SharedPtr<List> outlineList = doc->get_Lists()->Add(ListTemplate::OutlineNumbers);
builder->get_ListFormat()->set_List(outlineList);
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading1);
builder->Writeln(u"This is my Chapter 1");
// Create a numbered list.
SharedPtr<List> numberedList = doc->get_Lists()->Add(ListTemplate::NumberDefault);
builder->get_ListFormat()->set_List(numberedList);
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Normal);
builder->Writeln(u"Numbered list item 1.");
// Every paragraph that comprises a list will have this flag.
ASSERT_TRUE(builder->get_CurrentParagraph()->get_IsListItem());
ASSERT_TRUE(builder->get_ParagraphFormat()->get_IsListItem());
// Create a bulleted list.
SharedPtr<List> bulletedList = doc->get_Lists()->Add(ListTemplate::BulletDefault);
builder->get_ListFormat()->set_List(bulletedList);
builder->get_ParagraphFormat()->set_LeftIndent(72);
builder->Writeln(u"Bulleted list item 1.");
builder->Writeln(u"Bulleted list item 2.");
builder->get_ParagraphFormat()->ClearFormatting();
// Revert to the numbered list.
builder->get_ListFormat()->set_List(numberedList);
builder->Writeln(u"Numbered list item 2.");
builder->Writeln(u"Numbered list item 3.");
// Revert to the outline list.
builder->get_ListFormat()->set_List(outlineList);
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading1);
builder->Writeln(u"This is my Chapter 2");
builder->get_ParagraphFormat()->ClearFormatting();
builder->get_Document()->Save(ArtifactsDir + u"Lists.NestedLists.docx");

◆ get_AddSpaceBetweenFarEastAndAlpha()

bool Aspose::Words::ParagraphFormat::get_AddSpaceBetweenFarEastAndAlpha ( )

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.

Examples

Shows how to insert a paragraph into the document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Font> font = builder->get_Font();
font->set_Size(16);
font->set_Bold(true);
font->set_Name(u"Arial");
font->set_Underline(Underline::Dash);
SharedPtr<ParagraphFormat> paragraphFormat = builder->get_ParagraphFormat();
paragraphFormat->set_FirstLineIndent(8);
paragraphFormat->set_Alignment(ParagraphAlignment::Justify);
paragraphFormat->set_AddSpaceBetweenFarEastAndAlpha(true);
paragraphFormat->set_AddSpaceBetweenFarEastAndDigit(true);
paragraphFormat->set_KeepTogether(true);
// The "Writeln" method ends the paragraph after appending text
// and then starts a new line, adding a new paragraph.
builder->Writeln(u"Hello world!");
ASSERT_TRUE(builder->get_CurrentParagraph()->get_IsEndOfDocument());

◆ get_AddSpaceBetweenFarEastAndDigit()

bool Aspose::Words::ParagraphFormat::get_AddSpaceBetweenFarEastAndDigit ( )

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.

Examples

Shows how to insert a paragraph into the document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Font> font = builder->get_Font();
font->set_Size(16);
font->set_Bold(true);
font->set_Name(u"Arial");
font->set_Underline(Underline::Dash);
SharedPtr<ParagraphFormat> paragraphFormat = builder->get_ParagraphFormat();
paragraphFormat->set_FirstLineIndent(8);
paragraphFormat->set_Alignment(ParagraphAlignment::Justify);
paragraphFormat->set_AddSpaceBetweenFarEastAndAlpha(true);
paragraphFormat->set_AddSpaceBetweenFarEastAndDigit(true);
paragraphFormat->set_KeepTogether(true);
// The "Writeln" method ends the paragraph after appending text
// and then starts a new line, adding a new paragraph.
builder->Writeln(u"Hello world!");
ASSERT_TRUE(builder->get_CurrentParagraph()->get_IsEndOfDocument());

◆ get_Alignment()

Aspose::Words::ParagraphAlignment Aspose::Words::ParagraphFormat::get_Alignment ( )

Gets or sets text alignment for the paragraph.

Examples

Shows how to insert a paragraph into the document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Font> font = builder->get_Font();
font->set_Size(16);
font->set_Bold(true);
font->set_Name(u"Arial");
font->set_Underline(Underline::Dash);
SharedPtr<ParagraphFormat> paragraphFormat = builder->get_ParagraphFormat();
paragraphFormat->set_FirstLineIndent(8);
paragraphFormat->set_Alignment(ParagraphAlignment::Justify);
paragraphFormat->set_AddSpaceBetweenFarEastAndAlpha(true);
paragraphFormat->set_AddSpaceBetweenFarEastAndDigit(true);
paragraphFormat->set_KeepTogether(true);
// The "Writeln" method ends the paragraph after appending text
// and then starts a new line, adding a new paragraph.
builder->Writeln(u"Hello world!");
ASSERT_TRUE(builder->get_CurrentParagraph()->get_IsEndOfDocument());

Shows how to construct an Aspose.Words document by hand.

auto doc = MakeObject<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.
auto section = MakeObject<Section>(doc);
doc->AppendChild(section);
// Set some page setup properties for the section.
section->get_PageSetup()->set_SectionStart(SectionStart::NewPage);
section->get_PageSetup()->set_PaperSize(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.
auto body = MakeObject<Body>(doc);
section->AppendChild(body);
// Create a paragraph, set some formatting properties, and then append it as a child to the body.
auto para = MakeObject<Paragraph>(doc);
para->get_ParagraphFormat()->set_StyleName(u"Heading 1");
para->get_ParagraphFormat()->set_Alignment(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.
auto run = MakeObject<Run>(doc);
run->set_Text(u"Hello World!");
run->get_Font()->set_Color(System::Drawing::Color::get_Red());
para->AppendChild(run);
ASSERT_EQ(u"Hello World!", doc->GetText().Trim());
doc->Save(ArtifactsDir + u"Section.CreateManually.docx");

◆ get_Bidi()

bool Aspose::Words::ParagraphFormat::get_Bidi ( )

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.

Examples

Shows how to create right-to-left language-compatible lists with BIDIOUTLINE fields.

auto doc = MakeObject<Document>();
auto builder = MakeObject<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.".
auto field = System::DynamicCast<FieldBidiOutline>(builder->InsertField(FieldType::FieldBidiOutline, true));
builder->Writeln(u"שלום");
ASSERT_EQ(u" BIDIOUTLINE ", field->GetFieldCode());
// Add two more BIDIOUTLINE fields, which will display ".2" and ".3".
builder->InsertField(FieldType::FieldBidiOutline, true);
builder->Writeln(u"שלום");
builder->InsertField(FieldType::FieldBidiOutline, true);
builder->Writeln(u"שלום");
// Set the horizontal text alignment for every paragraph in the document to RTL.
for (const auto& para : System::IterateOver<Paragraph>(doc->GetChildNodes(NodeType::Paragraph, true)))
{
para->get_ParagraphFormat()->set_Bidi(true);
}
// If we enable a right-to-left editing language in Microsoft Word, our fields will display numbers.
// Otherwise, they will display "###".
doc->Save(ArtifactsDir + u"Field.BIDIOUTLINE.docx");

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.
auto loadOptions = MakeObject<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->set_DocumentDirection(DocumentDirection::Auto);
// Detect Hebrew text as right-to-left.
auto doc = MakeObject<Document>(MyDir + u"Hebrew text.txt", loadOptions);
ASSERT_TRUE(doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat()->get_Bidi());
// Detect English text as right-to-left.
doc = MakeObject<Document>(MyDir + u"English text.txt", loadOptions);
ASSERT_FALSE(doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat()->get_Bidi());

◆ get_Borders()

System::SharedPtr<Aspose::Words::BorderCollection> Aspose::Words::ParagraphFormat::get_Borders ( )

Gets collection of borders of the paragraph.

Examples

Shows how to insert a paragraph with a top border.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Border> topBorder = builder->get_ParagraphFormat()->get_Borders()->idx_get(BorderType::Top);
topBorder->set_Color(System::Drawing::Color::get_Red());
topBorder->set_LineWidth(4.0);
topBorder->set_LineStyle(LineStyle::DashSmallGap);
builder->Writeln(u"Text with a red top border.");
doc->Save(ArtifactsDir + u"Border.ParagraphTopBorder.docx");

◆ get_CharacterUnitFirstLineIndent()

double Aspose::Words::ParagraphFormat::get_CharacterUnitFirstLineIndent ( )

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.

Examples

Shows how to change paragraph spacing and indents.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<ParagraphFormat> format = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat();
// Below are five different spacing options, along with the properties that their configuration indirectly affects.
// 1 - Left indent:
ASPOSE_ASSERT_EQ(format->get_LeftIndent(), 0.0);
format->set_CharacterUnitLeftIndent(10.0);
ASPOSE_ASSERT_EQ(format->get_LeftIndent(), 120.0);
// 2 - Right indent:
ASPOSE_ASSERT_EQ(format->get_RightIndent(), 0.0);
format->set_CharacterUnitRightIndent(-5.5);
ASPOSE_ASSERT_EQ(format->get_RightIndent(), -66.0);
// 3 - Hanging indent:
ASPOSE_ASSERT_EQ(format->get_FirstLineIndent(), 0.0);
format->set_CharacterUnitFirstLineIndent(20.3);
ASSERT_NEAR(format->get_FirstLineIndent(), 243.59, 0.1);
// 4 - Line spacing before paragraphs:
ASPOSE_ASSERT_EQ(format->get_SpaceBefore(), 0.0);
format->set_LineUnitBefore(5.1);
ASSERT_NEAR(format->get_SpaceBefore(), 61.1, 0.1);
// 5 - Line spacing after paragraphs:
ASPOSE_ASSERT_EQ(format->get_SpaceAfter(), 0.0);
format->set_LineUnitAfter(10.9);
ASSERT_NEAR(format->get_SpaceAfter(), 130.8, 0.1);
builder->Writeln(String(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, ") +
u"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
builder->Write(String(u"测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试") +
u"文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档");

◆ get_CharacterUnitLeftIndent()

double Aspose::Words::ParagraphFormat::get_CharacterUnitLeftIndent ( )

Gets or sets the left indent value (in characters) for the specified paragraphs.

Examples

Shows how to change paragraph spacing and indents.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<ParagraphFormat> format = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat();
// Below are five different spacing options, along with the properties that their configuration indirectly affects.
// 1 - Left indent:
ASPOSE_ASSERT_EQ(format->get_LeftIndent(), 0.0);
format->set_CharacterUnitLeftIndent(10.0);
ASPOSE_ASSERT_EQ(format->get_LeftIndent(), 120.0);
// 2 - Right indent:
ASPOSE_ASSERT_EQ(format->get_RightIndent(), 0.0);
format->set_CharacterUnitRightIndent(-5.5);
ASPOSE_ASSERT_EQ(format->get_RightIndent(), -66.0);
// 3 - Hanging indent:
ASPOSE_ASSERT_EQ(format->get_FirstLineIndent(), 0.0);
format->set_CharacterUnitFirstLineIndent(20.3);
ASSERT_NEAR(format->get_FirstLineIndent(), 243.59, 0.1);
// 4 - Line spacing before paragraphs:
ASPOSE_ASSERT_EQ(format->get_SpaceBefore(), 0.0);
format->set_LineUnitBefore(5.1);
ASSERT_NEAR(format->get_SpaceBefore(), 61.1, 0.1);
// 5 - Line spacing after paragraphs:
ASPOSE_ASSERT_EQ(format->get_SpaceAfter(), 0.0);
format->set_LineUnitAfter(10.9);
ASSERT_NEAR(format->get_SpaceAfter(), 130.8, 0.1);
builder->Writeln(String(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, ") +
u"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
builder->Write(String(u"测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试") +
u"文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档");

◆ get_CharacterUnitRightIndent()

double Aspose::Words::ParagraphFormat::get_CharacterUnitRightIndent ( )

Gets or sets the right indent value (in characters) for the specified paragraphs.

Examples

Shows how to change paragraph spacing and indents.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<ParagraphFormat> format = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat();
// Below are five different spacing options, along with the properties that their configuration indirectly affects.
// 1 - Left indent:
ASPOSE_ASSERT_EQ(format->get_LeftIndent(), 0.0);
format->set_CharacterUnitLeftIndent(10.0);
ASPOSE_ASSERT_EQ(format->get_LeftIndent(), 120.0);
// 2 - Right indent:
ASPOSE_ASSERT_EQ(format->get_RightIndent(), 0.0);
format->set_CharacterUnitRightIndent(-5.5);
ASPOSE_ASSERT_EQ(format->get_RightIndent(), -66.0);
// 3 - Hanging indent:
ASPOSE_ASSERT_EQ(format->get_FirstLineIndent(), 0.0);
format->set_CharacterUnitFirstLineIndent(20.3);
ASSERT_NEAR(format->get_FirstLineIndent(), 243.59, 0.1);
// 4 - Line spacing before paragraphs:
ASPOSE_ASSERT_EQ(format->get_SpaceBefore(), 0.0);
format->set_LineUnitBefore(5.1);
ASSERT_NEAR(format->get_SpaceBefore(), 61.1, 0.1);
// 5 - Line spacing after paragraphs:
ASPOSE_ASSERT_EQ(format->get_SpaceAfter(), 0.0);
format->set_LineUnitAfter(10.9);
ASSERT_NEAR(format->get_SpaceAfter(), 130.8, 0.1);
builder->Writeln(String(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, ") +
u"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
builder->Write(String(u"测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试") +
u"文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档");

◆ get_DropCapPosition()

Aspose::Words::DropCapPosition Aspose::Words::ParagraphFormat::get_DropCapPosition ( )

Gets or sets the position for a drop cap text.

Examples

Shows how to nest a list inside another list.

auto doc = MakeObject<Document>();
auto builder = MakeObject<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.
SharedPtr<List> outlineList = doc->get_Lists()->Add(ListTemplate::OutlineNumbers);
builder->get_ListFormat()->set_List(outlineList);
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading1);
builder->Writeln(u"This is my Chapter 1");
// Create a numbered list.
SharedPtr<List> numberedList = doc->get_Lists()->Add(ListTemplate::NumberDefault);
builder->get_ListFormat()->set_List(numberedList);
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Normal);
builder->Writeln(u"Numbered list item 1.");
// Every paragraph that comprises a list will have this flag.
ASSERT_TRUE(builder->get_CurrentParagraph()->get_IsListItem());
ASSERT_TRUE(builder->get_ParagraphFormat()->get_IsListItem());
// Create a bulleted list.
SharedPtr<List> bulletedList = doc->get_Lists()->Add(ListTemplate::BulletDefault);
builder->get_ListFormat()->set_List(bulletedList);
builder->get_ParagraphFormat()->set_LeftIndent(72);
builder->Writeln(u"Bulleted list item 1.");
builder->Writeln(u"Bulleted list item 2.");
builder->get_ParagraphFormat()->ClearFormatting();
// Revert to the numbered list.
builder->get_ListFormat()->set_List(numberedList);
builder->Writeln(u"Numbered list item 2.");
builder->Writeln(u"Numbered list item 3.");
// Revert to the outline list.
builder->get_ListFormat()->set_List(outlineList);
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading1);
builder->Writeln(u"This is my Chapter 2");
builder->get_ParagraphFormat()->ClearFormatting();
builder->get_Document()->Save(ArtifactsDir + u"Lists.NestedLists.docx");

◆ get_FarEastLineBreakControl()

bool Aspose::Words::ParagraphFormat::get_FarEastLineBreakControl ( )

Gets or sets a flag indicating whether East Asian line-breaking rules are applied to the current paragraph.

Examples

Shows how to set special properties for Asian typography.

auto doc = MakeObject<Document>(MyDir + u"Document.docx");
SharedPtr<ParagraphFormat> format = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat();
format->set_FarEastLineBreakControl(true);
format->set_WordWrap(false);
format->set_HangingPunctuation(true);
doc->Save(ArtifactsDir + u"ParagraphFormat.AsianTypographyProperties.docx");

◆ get_FirstLineIndent()

double Aspose::Words::ParagraphFormat::get_FirstLineIndent ( )

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.

Examples

Shows how to insert a paragraph into the document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Font> font = builder->get_Font();
font->set_Size(16);
font->set_Bold(true);
font->set_Name(u"Arial");
font->set_Underline(Underline::Dash);
SharedPtr<ParagraphFormat> paragraphFormat = builder->get_ParagraphFormat();
paragraphFormat->set_FirstLineIndent(8);
paragraphFormat->set_Alignment(ParagraphAlignment::Justify);
paragraphFormat->set_AddSpaceBetweenFarEastAndAlpha(true);
paragraphFormat->set_AddSpaceBetweenFarEastAndDigit(true);
paragraphFormat->set_KeepTogether(true);
// The "Writeln" method ends the paragraph after appending text
// and then starts a new line, adding a new paragraph.
builder->Writeln(u"Hello world!");
ASSERT_TRUE(builder->get_CurrentParagraph()->get_IsEndOfDocument());

◆ get_HangingPunctuation()

bool Aspose::Words::ParagraphFormat::get_HangingPunctuation ( )

Gets or sets a flag indicating whether hanging punctuation is enabled for the current paragraph.

Examples

Shows how to set special properties for Asian typography.

auto doc = MakeObject<Document>(MyDir + u"Document.docx");
SharedPtr<ParagraphFormat> format = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat();
format->set_FarEastLineBreakControl(true);
format->set_WordWrap(false);
format->set_HangingPunctuation(true);
doc->Save(ArtifactsDir + u"ParagraphFormat.AsianTypographyProperties.docx");

◆ get_IsHeading()

bool Aspose::Words::ParagraphFormat::get_IsHeading ( )

True when the paragraph style is one of the built-in Heading styles.

Examples

Shows how to limit the headings' level that will appear in the outline of a saved PDF document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert headings that can serve as TOC entries of levels 1, 2, and then 3.
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading1);
ASSERT_TRUE(builder->get_ParagraphFormat()->get_IsHeading());
builder->Writeln(u"Heading 1");
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading2);
builder->Writeln(u"Heading 1.1");
builder->Writeln(u"Heading 1.2");
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading3);
builder->Writeln(u"Heading 1.2.1");
builder->Writeln(u"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.
auto saveOptions = MakeObject<PdfSaveOptions>();
saveOptions->set_SaveFormat(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->get_OutlineOptions()->set_HeadingsOutlineLevels(2);
doc->Save(ArtifactsDir + u"PdfSaveOptions.HeadingsOutlineLevels.pdf", saveOptions);

◆ get_IsListItem()

bool Aspose::Words::ParagraphFormat::get_IsListItem ( )

True when the paragraph is an item in a bulleted or numbered list.

Examples

Shows how to nest a list inside another list.

auto doc = MakeObject<Document>();
auto builder = MakeObject<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.
SharedPtr<List> outlineList = doc->get_Lists()->Add(ListTemplate::OutlineNumbers);
builder->get_ListFormat()->set_List(outlineList);
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading1);
builder->Writeln(u"This is my Chapter 1");
// Create a numbered list.
SharedPtr<List> numberedList = doc->get_Lists()->Add(ListTemplate::NumberDefault);
builder->get_ListFormat()->set_List(numberedList);
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Normal);
builder->Writeln(u"Numbered list item 1.");
// Every paragraph that comprises a list will have this flag.
ASSERT_TRUE(builder->get_CurrentParagraph()->get_IsListItem());
ASSERT_TRUE(builder->get_ParagraphFormat()->get_IsListItem());
// Create a bulleted list.
SharedPtr<List> bulletedList = doc->get_Lists()->Add(ListTemplate::BulletDefault);
builder->get_ListFormat()->set_List(bulletedList);
builder->get_ParagraphFormat()->set_LeftIndent(72);
builder->Writeln(u"Bulleted list item 1.");
builder->Writeln(u"Bulleted list item 2.");
builder->get_ParagraphFormat()->ClearFormatting();
// Revert to the numbered list.
builder->get_ListFormat()->set_List(numberedList);
builder->Writeln(u"Numbered list item 2.");
builder->Writeln(u"Numbered list item 3.");
// Revert to the outline list.
builder->get_ListFormat()->set_List(outlineList);
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading1);
builder->Writeln(u"This is my Chapter 2");
builder->get_ParagraphFormat()->ClearFormatting();
builder->get_Document()->Save(ArtifactsDir + u"Lists.NestedLists.docx");

◆ get_KeepTogether()

bool Aspose::Words::ParagraphFormat::get_KeepTogether ( )

True if all lines in the paragraph are to remain on the same page.

Examples

Shows how to insert a paragraph into the document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Font> font = builder->get_Font();
font->set_Size(16);
font->set_Bold(true);
font->set_Name(u"Arial");
font->set_Underline(Underline::Dash);
SharedPtr<ParagraphFormat> paragraphFormat = builder->get_ParagraphFormat();
paragraphFormat->set_FirstLineIndent(8);
paragraphFormat->set_Alignment(ParagraphAlignment::Justify);
paragraphFormat->set_AddSpaceBetweenFarEastAndAlpha(true);
paragraphFormat->set_AddSpaceBetweenFarEastAndDigit(true);
paragraphFormat->set_KeepTogether(true);
// The "Writeln" method ends the paragraph after appending text
// and then starts a new line, adding a new paragraph.
builder->Writeln(u"Hello world!");
ASSERT_TRUE(builder->get_CurrentParagraph()->get_IsEndOfDocument());

◆ get_KeepWithNext()

bool Aspose::Words::ParagraphFormat::get_KeepWithNext ( )

True if the paragraph is to remains on the same page as the paragraph that follows it.

Examples

Shows how to set a table to stay together on the same page.

auto doc = MakeObject<Document>(MyDir + u"Table spanning two pages.docx");
SharedPtr<Table> table = doc->get_FirstSection()->get_Body()->get_Tables()->idx_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 (const auto& cell : System::IterateOver(table->GetChildNodes(NodeType::Cell, true)->LINQ_OfType<SharedPtr<Cell>>()))
{
for (const auto& para : System::IterateOver(cell->get_Paragraphs()->LINQ_OfType<SharedPtr<Paragraph>>()))
{
ASSERT_TRUE(para->get_IsInCell());
if (!(cell->get_ParentRow()->get_IsLastRow() && para->get_IsEndOfCell()))
{
para->get_ParagraphFormat()->set_KeepWithNext(true);
}
}
}
doc->Save(ArtifactsDir + u"Table.KeepTableTogether.docx");

◆ get_LeftIndent()

double Aspose::Words::ParagraphFormat::get_LeftIndent ( )

Gets or sets the value (in points) that represents the left indent for paragraph.

Examples

Shows how to configure paragraph formatting to create off-center text.

auto doc = MakeObject<Document>();
auto builder = MakeObject<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.
SharedPtr<ParagraphFormat> paragraphFormat = builder->get_ParagraphFormat();
paragraphFormat->set_Alignment(ParagraphAlignment::Center);
paragraphFormat->set_LeftIndent(100);
paragraphFormat->set_RightIndent(50);
paragraphFormat->set_SpaceAfter(25);
builder->Writeln(u"This paragraph demonstrates how left and right indentation affects word wrapping.");
builder->Writeln(u"The space between the above paragraph and this one depends on the DocumentBuilder's paragraph format.");
doc->Save(ArtifactsDir + u"DocumentBuilder.SetParagraphFormatting.docx");

◆ get_LineSpacing()

double Aspose::Words::ParagraphFormat::get_LineSpacing ( )

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.

Examples

Shows how to work with line spacing.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Below are three line spacing rules that we can define using the
// paragraph's "LineSpacingRule" property to configure spacing between paragraphs.
// 1 - Set a minimum amount of spacing.
// This will give vertical padding to lines of text of any size
// that is too small to maintain the minimum line-height.
builder->get_ParagraphFormat()->set_LineSpacingRule(LineSpacingRule::AtLeast);
builder->get_ParagraphFormat()->set_LineSpacing(20);
builder->Writeln(u"Minimum line spacing of 20.");
builder->Writeln(u"Minimum line spacing of 20.");
// 2 - Set exact spacing.
// Using font sizes that are too large for the spacing will truncate the text.
builder->get_ParagraphFormat()->set_LineSpacingRule(LineSpacingRule::Exactly);
builder->get_ParagraphFormat()->set_LineSpacing(5);
builder->Writeln(u"Line spacing of exactly 5.");
builder->Writeln(u"Line spacing of exactly 5.");
// 3 - Set spacing as a multiple of default line spacing, which is 12 points by default.
// This kind of spacing will scale to different font sizes.
builder->get_ParagraphFormat()->set_LineSpacingRule(LineSpacingRule::Multiple);
builder->get_ParagraphFormat()->set_LineSpacing(18);
builder->Writeln(u"Line spacing of 1.5 default lines.");
builder->Writeln(u"Line spacing of 1.5 default lines.");
doc->Save(ArtifactsDir + u"ParagraphFormat.LineSpacing.docx");

◆ get_LineSpacingRule()

Aspose::Words::LineSpacingRule Aspose::Words::ParagraphFormat::get_LineSpacingRule ( )

Gets or sets the line spacing for the paragraph.

Examples

Shows how to work with line spacing.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Below are three line spacing rules that we can define using the
// paragraph's "LineSpacingRule" property to configure spacing between paragraphs.
// 1 - Set a minimum amount of spacing.
// This will give vertical padding to lines of text of any size
// that is too small to maintain the minimum line-height.
builder->get_ParagraphFormat()->set_LineSpacingRule(LineSpacingRule::AtLeast);
builder->get_ParagraphFormat()->set_LineSpacing(20);
builder->Writeln(u"Minimum line spacing of 20.");
builder->Writeln(u"Minimum line spacing of 20.");
// 2 - Set exact spacing.
// Using font sizes that are too large for the spacing will truncate the text.
builder->get_ParagraphFormat()->set_LineSpacingRule(LineSpacingRule::Exactly);
builder->get_ParagraphFormat()->set_LineSpacing(5);
builder->Writeln(u"Line spacing of exactly 5.");
builder->Writeln(u"Line spacing of exactly 5.");
// 3 - Set spacing as a multiple of default line spacing, which is 12 points by default.
// This kind of spacing will scale to different font sizes.
builder->get_ParagraphFormat()->set_LineSpacingRule(LineSpacingRule::Multiple);
builder->get_ParagraphFormat()->set_LineSpacing(18);
builder->Writeln(u"Line spacing of 1.5 default lines.");
builder->Writeln(u"Line spacing of 1.5 default lines.");
doc->Save(ArtifactsDir + u"ParagraphFormat.LineSpacing.docx");

◆ get_LinesToDrop()

int32_t Aspose::Words::ParagraphFormat::get_LinesToDrop ( )

Gets or sets the number of lines of the paragraph text used to calculate the drop cap height.

Examples

Shows how to set the size of a drop cap.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Modify the "LinesToDrop" property to designate a paragraph as a drop cap,
// which will turn it into a large capital letter that will decorate the next paragraph.
// Give this property a value of 4 to give the drop cap the height of four text lines.
builder->get_ParagraphFormat()->set_LinesToDrop(4);
builder->Writeln(u"H");
// Reset the "LinesToDrop" property to 0 to turn the next paragraph into an ordinary paragraph.
// The text in this paragraph will wrap around the drop cap.
builder->get_ParagraphFormat()->set_LinesToDrop(0);
builder->Writeln(u"ello world!");
doc->Save(ArtifactsDir + u"ParagraphFormat.LinesToDrop.odt");

◆ get_LineUnitAfter()

double Aspose::Words::ParagraphFormat::get_LineUnitAfter ( )

Gets or sets the amount of spacing (in gridlines) after the paragraphs.

Examples

Shows how to change paragraph spacing and indents.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<ParagraphFormat> format = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat();
// Below are five different spacing options, along with the properties that their configuration indirectly affects.
// 1 - Left indent:
ASPOSE_ASSERT_EQ(format->get_LeftIndent(), 0.0);
format->set_CharacterUnitLeftIndent(10.0);
ASPOSE_ASSERT_EQ(format->get_LeftIndent(), 120.0);
// 2 - Right indent:
ASPOSE_ASSERT_EQ(format->get_RightIndent(), 0.0);
format->set_CharacterUnitRightIndent(-5.5);
ASPOSE_ASSERT_EQ(format->get_RightIndent(), -66.0);
// 3 - Hanging indent:
ASPOSE_ASSERT_EQ(format->get_FirstLineIndent(), 0.0);
format->set_CharacterUnitFirstLineIndent(20.3);
ASSERT_NEAR(format->get_FirstLineIndent(), 243.59, 0.1);
// 4 - Line spacing before paragraphs:
ASPOSE_ASSERT_EQ(format->get_SpaceBefore(), 0.0);
format->set_LineUnitBefore(5.1);
ASSERT_NEAR(format->get_SpaceBefore(), 61.1, 0.1);
// 5 - Line spacing after paragraphs:
ASPOSE_ASSERT_EQ(format->get_SpaceAfter(), 0.0);
format->set_LineUnitAfter(10.9);
ASSERT_NEAR(format->get_SpaceAfter(), 130.8, 0.1);
builder->Writeln(String(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, ") +
u"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
builder->Write(String(u"测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试") +
u"文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档");

◆ get_LineUnitBefore()

double Aspose::Words::ParagraphFormat::get_LineUnitBefore ( )

Gets or sets the amount of spacing (in gridlines) before the paragraphs.

Examples

Shows how to change paragraph spacing and indents.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<ParagraphFormat> format = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat();
// Below are five different spacing options, along with the properties that their configuration indirectly affects.
// 1 - Left indent:
ASPOSE_ASSERT_EQ(format->get_LeftIndent(), 0.0);
format->set_CharacterUnitLeftIndent(10.0);
ASPOSE_ASSERT_EQ(format->get_LeftIndent(), 120.0);
// 2 - Right indent:
ASPOSE_ASSERT_EQ(format->get_RightIndent(), 0.0);
format->set_CharacterUnitRightIndent(-5.5);
ASPOSE_ASSERT_EQ(format->get_RightIndent(), -66.0);
// 3 - Hanging indent:
ASPOSE_ASSERT_EQ(format->get_FirstLineIndent(), 0.0);
format->set_CharacterUnitFirstLineIndent(20.3);
ASSERT_NEAR(format->get_FirstLineIndent(), 243.59, 0.1);
// 4 - Line spacing before paragraphs:
ASPOSE_ASSERT_EQ(format->get_SpaceBefore(), 0.0);
format->set_LineUnitBefore(5.1);
ASSERT_NEAR(format->get_SpaceBefore(), 61.1, 0.1);
// 5 - Line spacing after paragraphs:
ASPOSE_ASSERT_EQ(format->get_SpaceAfter(), 0.0);
format->set_LineUnitAfter(10.9);
ASSERT_NEAR(format->get_SpaceAfter(), 130.8, 0.1);
builder->Writeln(String(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, ") +
u"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
builder->Write(String(u"测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试") +
u"文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档");

◆ get_NoSpaceBetweenParagraphsOfSameStyle()

bool Aspose::Words::ParagraphFormat::get_NoSpaceBetweenParagraphsOfSameStyle ( )

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.

Examples

Shows how to apply no spacing between paragraphs with the same style.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Apply a large amount of spacing before and after paragraphs that this builder will create.
builder->get_ParagraphFormat()->set_SpaceBefore(24);
builder->get_ParagraphFormat()->set_SpaceAfter(24);
// Set the "NoSpaceBetweenParagraphsOfSameStyle" flag to "true" to apply
// no spacing between paragraphs with the same style, which will group similar paragraphs.
// Leave the "NoSpaceBetweenParagraphsOfSameStyle" flag as "false"
// to evenly apply spacing to every paragraph.
builder->get_ParagraphFormat()->set_NoSpaceBetweenParagraphsOfSameStyle(noSpaceBetweenParagraphsOfSameStyle);
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Normal"));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Quote"));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Normal"));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
doc->Save(ArtifactsDir + u"ParagraphFormat.ParagraphSpacingSameStyle.docx");

◆ get_OutlineLevel()

Aspose::Words::OutlineLevel Aspose::Words::ParagraphFormat::get_OutlineLevel ( )

Specifies the outline level of the paragraph in the document.

Examples

Shows how to configure paragraph outline levels to create collapsible text.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Each paragraph has an OutlineLevel, which could be any number from 1 to 9, or at the default "BodyText" value.
// Setting the property to one of the numbered values will show an arrow to the left
// of the beginning of the paragraph.
builder->get_ParagraphFormat()->set_OutlineLevel(OutlineLevel::Level1);
builder->Writeln(u"Paragraph outline level 1.");
// Level 1 is the topmost level. If there is a paragraph with a lower level below a paragraph with a higher level,
// collapsing the higher-level paragraph will collapse the lower level paragraph.
builder->get_ParagraphFormat()->set_OutlineLevel(OutlineLevel::Level2);
builder->Writeln(u"Paragraph outline level 2.");
// Two paragraphs of the same level will not collapse each other,
// and the arrows do not collapse the paragraphs they point to.
builder->get_ParagraphFormat()->set_OutlineLevel(OutlineLevel::Level3);
builder->Writeln(u"Paragraph outline level 3.");
builder->Writeln(u"Paragraph outline level 3.");
// The default "BodyText" value is the lowest, which a paragraph of any level can collapse.
builder->get_ParagraphFormat()->set_OutlineLevel(OutlineLevel::BodyText);
builder->Writeln(u"Paragraph at main text level.");
doc->Save(ArtifactsDir + u"ParagraphFormat.ParagraphOutlineLevel.docx");

◆ get_PageBreakBefore()

bool Aspose::Words::ParagraphFormat::get_PageBreakBefore ( )

True if a page break is forced before the paragraph.

Examples

Shows how to create paragraphs with page breaks at the beginning.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Set this flag to "true" to apply a page break to each paragraph's beginning
// that the document builder will create under this ParagraphFormat configuration.
// The first paragraph will not receive a page break.
// Leave this flag as "false" to start each new paragraph on the same page
// as the previous, provided there is sufficient space.
builder->get_ParagraphFormat()->set_PageBreakBefore(pageBreakBefore);
builder->Writeln(u"Paragraph 1.");
builder->Writeln(u"Paragraph 2.");
auto layoutCollector = MakeObject<LayoutCollector>(doc);
SharedPtr<ParagraphCollection> paragraphs = doc->get_FirstSection()->get_Body()->get_Paragraphs();
if (pageBreakBefore)
{
ASSERT_EQ(1, layoutCollector->GetStartPageIndex(paragraphs->idx_get(0)));
ASSERT_EQ(2, layoutCollector->GetStartPageIndex(paragraphs->idx_get(1)));
}
else
{
ASSERT_EQ(1, layoutCollector->GetStartPageIndex(paragraphs->idx_get(0)));
ASSERT_EQ(1, layoutCollector->GetStartPageIndex(paragraphs->idx_get(1)));
}
doc->Save(ArtifactsDir + u"ParagraphFormat.PageBreakBefore.docx");

◆ get_RightIndent()

double Aspose::Words::ParagraphFormat::get_RightIndent ( )

Gets or sets the value (in points) that represents the right indent for paragraph.

Examples

Shows how to configure paragraph formatting to create off-center text.

auto doc = MakeObject<Document>();
auto builder = MakeObject<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.
SharedPtr<ParagraphFormat> paragraphFormat = builder->get_ParagraphFormat();
paragraphFormat->set_Alignment(ParagraphAlignment::Center);
paragraphFormat->set_LeftIndent(100);
paragraphFormat->set_RightIndent(50);
paragraphFormat->set_SpaceAfter(25);
builder->Writeln(u"This paragraph demonstrates how left and right indentation affects word wrapping.");
builder->Writeln(u"The space between the above paragraph and this one depends on the DocumentBuilder's paragraph format.");
doc->Save(ArtifactsDir + u"DocumentBuilder.SetParagraphFormatting.docx");

◆ get_Shading()

System::SharedPtr<Aspose::Words::Shading> Aspose::Words::ParagraphFormat::get_Shading ( )

Returns a Shading object that refers to the shading formatting for the paragraph.

Examples

Shows how to decorate text with borders and shading.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<BorderCollection> borders = builder->get_ParagraphFormat()->get_Borders();
borders->set_DistanceFromText(20);
borders->idx_get(BorderType::Left)->set_LineStyle(LineStyle::Double);
borders->idx_get(BorderType::Right)->set_LineStyle(LineStyle::Double);
borders->idx_get(BorderType::Top)->set_LineStyle(LineStyle::Double);
borders->idx_get(BorderType::Bottom)->set_LineStyle(LineStyle::Double);
SharedPtr<Shading> shading = builder->get_ParagraphFormat()->get_Shading();
shading->set_Texture(TextureIndex::TextureDiagonalCross);
shading->set_BackgroundPatternColor(System::Drawing::Color::get_LightCoral());
shading->set_ForegroundPatternColor(System::Drawing::Color::get_LightSalmon());
builder->Write(u"This paragraph is formatted with a double border and shading.");
doc->Save(ArtifactsDir + u"DocumentBuilder.ApplyBordersAndShading.docx");

◆ get_SnapToGrid()

bool Aspose::Words::ParagraphFormat::get_SnapToGrid ( )

Specifies whether the current paragraph should use the document grid lines per page settings when laying out the contents in the paragraph.

Examples

Shows how to specify a limit for the number of lines that each page may have.

auto doc = MakeObject<Document>();
auto builder = MakeObject<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->get_PageSetup()->set_LayoutMode(SectionLayoutMode::LineGrid);
builder->get_PageSetup()->set_LinesPerPage(15);
builder->get_ParagraphFormat()->set_SnapToGrid(true);
for (int i = 0; i < 30; i++)
{
builder->Write(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ");
}
doc->Save(ArtifactsDir + u"PageSetup.LinesPerPage.docx");

◆ get_SpaceAfter()

double Aspose::Words::ParagraphFormat::get_SpaceAfter ( )

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.

Exceptions
System::ArgumentOutOfRangeExceptionThrows when argument was out of the range of valid values.
Examples

Shows how to set automatic paragraph spacing.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Apply a large amount of spacing before and after paragraphs that this builder will create.
builder->get_ParagraphFormat()->set_SpaceBefore(24);
builder->get_ParagraphFormat()->set_SpaceAfter(24);
// Set these flags to "true" to apply automatic spacing,
// effectively ignoring the spacing in the properties we set above.
// Leave them as "false" will apply our custom paragraph spacing.
builder->get_ParagraphFormat()->set_SpaceAfterAuto(autoSpacing);
builder->get_ParagraphFormat()->set_SpaceBeforeAuto(autoSpacing);
// Insert two paragraphs that will have spacing above and below them and save the document.
builder->Writeln(u"Paragraph 1.");
builder->Writeln(u"Paragraph 2.");
doc->Save(ArtifactsDir + u"ParagraphFormat.ParagraphSpacingAuto.docx");

Shows how to apply no spacing between paragraphs with the same style.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Apply a large amount of spacing before and after paragraphs that this builder will create.
builder->get_ParagraphFormat()->set_SpaceBefore(24);
builder->get_ParagraphFormat()->set_SpaceAfter(24);
// Set the "NoSpaceBetweenParagraphsOfSameStyle" flag to "true" to apply
// no spacing between paragraphs with the same style, which will group similar paragraphs.
// Leave the "NoSpaceBetweenParagraphsOfSameStyle" flag as "false"
// to evenly apply spacing to every paragraph.
builder->get_ParagraphFormat()->set_NoSpaceBetweenParagraphsOfSameStyle(noSpaceBetweenParagraphsOfSameStyle);
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Normal"));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Quote"));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Normal"));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
doc->Save(ArtifactsDir + u"ParagraphFormat.ParagraphSpacingSameStyle.docx");

◆ get_SpaceAfterAuto()

bool Aspose::Words::ParagraphFormat::get_SpaceAfterAuto ( )

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.
Examples

Shows how to set automatic paragraph spacing.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Apply a large amount of spacing before and after paragraphs that this builder will create.
builder->get_ParagraphFormat()->set_SpaceBefore(24);
builder->get_ParagraphFormat()->set_SpaceAfter(24);
// Set these flags to "true" to apply automatic spacing,
// effectively ignoring the spacing in the properties we set above.
// Leave them as "false" will apply our custom paragraph spacing.
builder->get_ParagraphFormat()->set_SpaceAfterAuto(autoSpacing);
builder->get_ParagraphFormat()->set_SpaceBeforeAuto(autoSpacing);
// Insert two paragraphs that will have spacing above and below them and save the document.
builder->Writeln(u"Paragraph 1.");
builder->Writeln(u"Paragraph 2.");
doc->Save(ArtifactsDir + u"ParagraphFormat.ParagraphSpacingAuto.docx");

◆ get_SpaceBefore()

double Aspose::Words::ParagraphFormat::get_SpaceBefore ( )

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.

Exceptions
System::ArgumentOutOfRangeExceptionThrows when argument was out of the range of valid values.
Examples

Shows how to set automatic paragraph spacing.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Apply a large amount of spacing before and after paragraphs that this builder will create.
builder->get_ParagraphFormat()->set_SpaceBefore(24);
builder->get_ParagraphFormat()->set_SpaceAfter(24);
// Set these flags to "true" to apply automatic spacing,
// effectively ignoring the spacing in the properties we set above.
// Leave them as "false" will apply our custom paragraph spacing.
builder->get_ParagraphFormat()->set_SpaceAfterAuto(autoSpacing);
builder->get_ParagraphFormat()->set_SpaceBeforeAuto(autoSpacing);
// Insert two paragraphs that will have spacing above and below them and save the document.
builder->Writeln(u"Paragraph 1.");
builder->Writeln(u"Paragraph 2.");
doc->Save(ArtifactsDir + u"ParagraphFormat.ParagraphSpacingAuto.docx");

Shows how to apply no spacing between paragraphs with the same style.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Apply a large amount of spacing before and after paragraphs that this builder will create.
builder->get_ParagraphFormat()->set_SpaceBefore(24);
builder->get_ParagraphFormat()->set_SpaceAfter(24);
// Set the "NoSpaceBetweenParagraphsOfSameStyle" flag to "true" to apply
// no spacing between paragraphs with the same style, which will group similar paragraphs.
// Leave the "NoSpaceBetweenParagraphsOfSameStyle" flag as "false"
// to evenly apply spacing to every paragraph.
builder->get_ParagraphFormat()->set_NoSpaceBetweenParagraphsOfSameStyle(noSpaceBetweenParagraphsOfSameStyle);
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Normal"));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Quote"));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Normal"));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
builder->Writeln(String::Format(u"Paragraph in the \"{0}\" style.", builder->get_ParagraphFormat()->get_Style()->get_Name()));
doc->Save(ArtifactsDir + u"ParagraphFormat.ParagraphSpacingSameStyle.docx");

◆ get_SpaceBeforeAuto()

bool Aspose::Words::ParagraphFormat::get_SpaceBeforeAuto ( )

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.
Examples

Shows how to set automatic paragraph spacing.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Apply a large amount of spacing before and after paragraphs that this builder will create.
builder->get_ParagraphFormat()->set_SpaceBefore(24);
builder->get_ParagraphFormat()->set_SpaceAfter(24);
// Set these flags to "true" to apply automatic spacing,
// effectively ignoring the spacing in the properties we set above.
// Leave them as "false" will apply our custom paragraph spacing.
builder->get_ParagraphFormat()->set_SpaceAfterAuto(autoSpacing);
builder->get_ParagraphFormat()->set_SpaceBeforeAuto(autoSpacing);
// Insert two paragraphs that will have spacing above and below them and save the document.
builder->Writeln(u"Paragraph 1.");
builder->Writeln(u"Paragraph 2.");
doc->Save(ArtifactsDir + u"ParagraphFormat.ParagraphSpacingAuto.docx");

◆ get_Style()

System::SharedPtr<Aspose::Words::Style> Aspose::Words::ParagraphFormat::get_Style ( )

Gets or sets the paragraph style applied to this formatting.

Examples

Shows how to create and use a paragraph style with list formatting.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Create a custom paragraph style.
SharedPtr<Style> style = doc->get_Styles()->Add(StyleType::Paragraph, u"MyStyle1");
style->get_Font()->set_Size(24);
style->get_Font()->set_Name(u"Verdana");
style->get_ParagraphFormat()->set_SpaceAfter(12);
// Create a list and make sure the paragraphs that use this style will use this list.
style->get_ListFormat()->set_List(doc->get_Lists()->Add(ListTemplate::BulletDefault));
style->get_ListFormat()->set_ListLevelNumber(0);
// Apply the paragraph style to the document builder's current paragraph, and then add some text.
builder->get_ParagraphFormat()->set_Style(style);
builder->Writeln(u"Hello World: MyStyle1, bulleted list.");
// Change the document builder's style to one that has no list formatting and write another paragraph.
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Normal"));
builder->Writeln(u"Hello World: Normal.");
builder->get_Document()->Save(ArtifactsDir + u"Styles.ParagraphStyleBulletedList.docx");

◆ get_StyleIdentifier()

Aspose::Words::StyleIdentifier Aspose::Words::ParagraphFormat::get_StyleIdentifier ( )

Gets or sets the locale independent style identifier of the paragraph style applied to this formatting.

Examples

Shows how to insert a Table of contents (TOC) into a document using heading styles as entries.

auto doc = MakeObject<Document>();
auto builder = MakeObject<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(u"\\o \"1-3\" \\h \\z \\u");
builder->InsertBreak(BreakType::PageBreak);
// 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->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading1);
builder->Writeln(u"Heading 1");
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading2);
builder->Writeln(u"Heading 1.1");
builder->Writeln(u"Heading 1.2");
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading1);
builder->Writeln(u"Heading 2");
builder->Writeln(u"Heading 3");
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading2);
builder->Writeln(u"Heading 3.1");
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading3);
builder->Writeln(u"Heading 3.1.1");
builder->Writeln(u"Heading 3.1.2");
builder->Writeln(u"Heading 3.1.3");
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading4);
builder->Writeln(u"Heading 3.1.3.1");
builder->Writeln(u"Heading 3.1.3.2");
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Heading2);
builder->Writeln(u"Heading 3.2");
builder->Writeln(u"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(ArtifactsDir + u"DocumentBuilder.InsertToc.docx");

◆ get_StyleName()

System::String Aspose::Words::ParagraphFormat::get_StyleName ( )

Gets or sets the name of the paragraph style applied to this formatting.

Examples

Shows how to construct an Aspose.Words document by hand.

auto doc = MakeObject<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.
auto section = MakeObject<Section>(doc);
doc->AppendChild(section);
// Set some page setup properties for the section.
section->get_PageSetup()->set_SectionStart(SectionStart::NewPage);
section->get_PageSetup()->set_PaperSize(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.
auto body = MakeObject<Body>(doc);
section->AppendChild(body);
// Create a paragraph, set some formatting properties, and then append it as a child to the body.
auto para = MakeObject<Paragraph>(doc);
para->get_ParagraphFormat()->set_StyleName(u"Heading 1");
para->get_ParagraphFormat()->set_Alignment(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.
auto run = MakeObject<Run>(doc);
run->set_Text(u"Hello World!");
run->get_Font()->set_Color(System::Drawing::Color::get_Red());
para->AppendChild(run);
ASSERT_EQ(u"Hello World!", doc->GetText().Trim());
doc->Save(ArtifactsDir + u"Section.CreateManually.docx");

◆ get_SuppressAutoHyphens()

bool Aspose::Words::ParagraphFormat::get_SuppressAutoHyphens ( )

Specifies whether the current paragraph should be exempted from any hyphenation which is applied in the document settings.

Examples

Shows how to suppress hyphenation for a paragraph.

Hyphenation::RegisterDictionary(u"de-CH", MyDir + u"hyph_de_CH.dic");
ASSERT_TRUE(Hyphenation::IsDictionaryRegistered(u"de-CH"));
// Open a document containing text with a locale matching that of our dictionary.
// When we save this document to a fixed page save format, its text will have hyphenation.
auto doc = MakeObject<Document>(MyDir + u"German text.docx");
// We can set the "SuppressAutoHyphens" property to "true" to disable hyphenation
// for a specific paragraph while keeping it enabled for the rest of the document.
// The default value for this property is "false",
// which means every paragraph by default uses hyphenation if any is available.
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat()->set_SuppressAutoHyphens(suppressAutoHyphens);
doc->Save(ArtifactsDir + u"ParagraphFormat.SuppressHyphens.pdf");

◆ get_SuppressLineNumbers()

bool Aspose::Words::ParagraphFormat::get_SuppressLineNumbers ( )

Specifies whether the current paragraph's lines should be exempted from line numbering which is applied in the parent section.

Examples

Shows how to enable line numbering for a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<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.
SharedPtr<PageSetup> pageSetup = builder->get_PageSetup();
pageSetup->set_LineStartingNumber(1);
pageSetup->set_LineNumberCountBy(3);
pageSetup->set_LineNumberRestartMode(LineNumberRestartMode::RestartPage);
pageSetup->set_LineNumberDistanceFromText(50.0);
for (int i = 1; i <= 25; i++)
{
builder->Writeln(String::Format(u"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->get_FirstSection()->get_Body()->get_Paragraphs()->idx_get(14)->get_ParagraphFormat()->set_SuppressLineNumbers(true);
doc->Save(ArtifactsDir + u"PageSetup.LineNumbers.docx");

◆ get_TabStops()

System::SharedPtr<Aspose::Words::TabStopCollection> Aspose::Words::ParagraphFormat::get_TabStops ( )

Gets the collection of custom tab stops defined for this object.

Examples

Shows how to modify the position of the right tab stop in TOC related paragraphs.

auto doc = MakeObject<Document>(MyDir + u"Table of contents.docx");
// Iterate through all paragraphs with TOC result-based styles; this is any style between TOC and TOC9.
for (const auto& para : System::IterateOver(doc->GetChildNodes(NodeType::Paragraph, true)->LINQ_OfType<SharedPtr<Paragraph>>()))
{
if (para->get_ParagraphFormat()->get_Style()->get_StyleIdentifier() >= StyleIdentifier::Toc1 &&
para->get_ParagraphFormat()->get_Style()->get_StyleIdentifier() <= StyleIdentifier::Toc9)
{
// Get the first tab used in this paragraph, this should be the tab used to align the page numbers.
SharedPtr<TabStop> tab = para->get_ParagraphFormat()->get_TabStops()->idx_get(0);
// Replace the first default tab, stop with a custom tab stop.
para->get_ParagraphFormat()->get_TabStops()->RemoveByPosition(tab->get_Position());
para->get_ParagraphFormat()->get_TabStops()->Add(tab->get_Position() - 50, tab->get_Alignment(), tab->get_Leader());
}
}
doc->Save(ArtifactsDir + u"Styles.ChangeTocsTabStops.docx");

◆ get_WidowControl()

bool Aspose::Words::ParagraphFormat::get_WidowControl ( )

True if the first and last lines in the paragraph are to remain on the same page as the rest of the paragraph.

Examples

Shows how to enable widow/orphan control for a paragraph.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// When we write the text that does not fit onto one page, one line may spill over onto the next page.
// The single line that ends up on the next page is called an "Orphan",
// and the previous line where the orphan broke off is called a "Widow".
// We can fix orphans and widows by rearranging text via font size, spacing, or page margins.
// If we wish to preserve our document's dimensions, we can set this flag to "true"
// to push widows onto the same page as their respective orphans.
// Leave this flag as "false" will leave widow/orphan pairs in text.
// Every paragraph has this setting accessible in Microsoft Word via Home -> Paragraph -> Paragraph Settings
// (button on bottom right hand corner of "Paragraph" tab) -> "Widow/Orphan control".
builder->get_ParagraphFormat()->set_WidowControl(widowControl);
// Insert text that produces an orphan and a widow.
builder->get_Font()->set_Size(68);
builder->Write(String(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, ") +
u"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
doc->Save(ArtifactsDir + u"ParagraphFormat.WidowControl.docx");

◆ get_WordWrap()

bool Aspose::Words::ParagraphFormat::get_WordWrap ( )

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.

Examples

Shows how to set special properties for Asian typography.

auto doc = MakeObject<Document>(MyDir + u"Document.docx");
SharedPtr<ParagraphFormat> format = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat();
format->set_FarEastLineBreakControl(true);
format->set_WordWrap(false);
format->set_HangingPunctuation(true);
doc->Save(ArtifactsDir + u"ParagraphFormat.AsianTypographyProperties.docx");

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::ParagraphFormat::GetType ( ) const
overridevirtual

◆ Is()

virtual bool Aspose::Words::ParagraphFormat::Is ( const System::TypeInfo target) const
overridevirtual

◆ set_AddSpaceBetweenFarEastAndAlpha()

void Aspose::Words::ParagraphFormat::set_AddSpaceBetweenFarEastAndAlpha ( bool  value)

◆ set_AddSpaceBetweenFarEastAndDigit()

void Aspose::Words::ParagraphFormat::set_AddSpaceBetweenFarEastAndDigit ( bool  value)

◆ set_Alignment()

void Aspose::Words::ParagraphFormat::set_Alignment ( Aspose::Words::ParagraphAlignment  value)

◆ set_Bidi()

void Aspose::Words::ParagraphFormat::set_Bidi ( bool  value)

◆ set_CharacterUnitFirstLineIndent()

void Aspose::Words::ParagraphFormat::set_CharacterUnitFirstLineIndent ( double  value)

◆ set_CharacterUnitLeftIndent()

void Aspose::Words::ParagraphFormat::set_CharacterUnitLeftIndent ( double  value)

◆ set_CharacterUnitRightIndent()

void Aspose::Words::ParagraphFormat::set_CharacterUnitRightIndent ( double  value)

◆ set_DropCapPosition()

void Aspose::Words::ParagraphFormat::set_DropCapPosition ( Aspose::Words::DropCapPosition  value)

◆ set_FarEastLineBreakControl()

void Aspose::Words::ParagraphFormat::set_FarEastLineBreakControl ( bool  value)

◆ set_FirstLineIndent()

void Aspose::Words::ParagraphFormat::set_FirstLineIndent ( double  value)

◆ set_HangingPunctuation()

void Aspose::Words::ParagraphFormat::set_HangingPunctuation ( bool  value)

◆ set_KeepTogether()

void Aspose::Words::ParagraphFormat::set_KeepTogether ( bool  value)

◆ set_KeepWithNext()

void Aspose::Words::ParagraphFormat::set_KeepWithNext ( bool  value)

◆ set_LeftIndent()

void Aspose::Words::ParagraphFormat::set_LeftIndent ( double  value)

◆ set_LineSpacing()

void Aspose::Words::ParagraphFormat::set_LineSpacing ( double  value)

◆ set_LineSpacingRule()

void Aspose::Words::ParagraphFormat::set_LineSpacingRule ( Aspose::Words::LineSpacingRule  value)

◆ set_LinesToDrop()

void Aspose::Words::ParagraphFormat::set_LinesToDrop ( int32_t  value)

◆ set_LineUnitAfter()

void Aspose::Words::ParagraphFormat::set_LineUnitAfter ( double  value)

◆ set_LineUnitBefore()

void Aspose::Words::ParagraphFormat::set_LineUnitBefore ( double  value)

◆ set_NoSpaceBetweenParagraphsOfSameStyle()

void Aspose::Words::ParagraphFormat::set_NoSpaceBetweenParagraphsOfSameStyle ( bool  value)

◆ set_OutlineLevel()

void Aspose::Words::ParagraphFormat::set_OutlineLevel ( Aspose::Words::OutlineLevel  value)

◆ set_PageBreakBefore()

void Aspose::Words::ParagraphFormat::set_PageBreakBefore ( bool  value)

◆ set_RightIndent()

void Aspose::Words::ParagraphFormat::set_RightIndent ( double  value)

◆ set_SnapToGrid()

void Aspose::Words::ParagraphFormat::set_SnapToGrid ( bool  value)

◆ set_SpaceAfter()

void Aspose::Words::ParagraphFormat::set_SpaceAfter ( double  value)

◆ set_SpaceAfterAuto()

void Aspose::Words::ParagraphFormat::set_SpaceAfterAuto ( bool  value)

◆ set_SpaceBefore()

void Aspose::Words::ParagraphFormat::set_SpaceBefore ( double  value)

◆ set_SpaceBeforeAuto()

void Aspose::Words::ParagraphFormat::set_SpaceBeforeAuto ( bool  value)

◆ set_Style()

void Aspose::Words::ParagraphFormat::set_Style ( const System::SharedPtr< Aspose::Words::Style > &  value)

◆ set_StyleIdentifier()

void Aspose::Words::ParagraphFormat::set_StyleIdentifier ( Aspose::Words::StyleIdentifier  value)

◆ set_StyleName()

void Aspose::Words::ParagraphFormat::set_StyleName ( const System::String value)

◆ set_SuppressAutoHyphens()

void Aspose::Words::ParagraphFormat::set_SuppressAutoHyphens ( bool  value)

◆ set_SuppressLineNumbers()

void Aspose::Words::ParagraphFormat::set_SuppressLineNumbers ( bool  value)

◆ set_WidowControl()

void Aspose::Words::ParagraphFormat::set_WidowControl ( bool  value)

◆ set_WordWrap()

void Aspose::Words::ParagraphFormat::set_WordWrap ( bool  value)

◆ Type()

static const System::TypeInfo& Aspose::Words::ParagraphFormat::Type ( )
static