Aspose::Words::PageSetup Class Reference

Detailed Description

Represents the page setup properties of a section.

PageSetup object contains all the page setup attributes of a section (left margin, bottom margin, paper size, and so on) as properties.

Examples

Shows how to apply and revert page setup settings to sections in a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Modify the page setup properties for the builder's current section and add text.
builder->get_PageSetup()->set_Orientation(Orientation::Landscape);
builder->get_PageSetup()->set_VerticalAlignment(PageVerticalAlignment::Center);
builder->Writeln(u"This is the first section, which landscape oriented with vertically centered text.");
// If we start a new section using a document builder,
// it will inherit the builder's current page setup properties.
builder->InsertBreak(BreakType::SectionBreakNewPage);
ASSERT_EQ(Orientation::Landscape, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_Orientation());
ASSERT_EQ(PageVerticalAlignment::Center, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_VerticalAlignment());
// We can revert its page setup properties to their default values using the "ClearFormatting" method.
builder->get_PageSetup()->ClearFormatting();
ASSERT_EQ(Orientation::Portrait, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_Orientation());
ASSERT_EQ(PageVerticalAlignment::Top, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_VerticalAlignment());
builder->Writeln(u"This is the second section, which is in default Letter paper size, portrait orientation and top alignment.");
doc->Save(ArtifactsDir + u"PageSetup.ClearFormatting.docx");

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

+ Inheritance diagram for Aspose::Words::PageSetup:

Public Member Functions

void ClearFormatting ()
 Resets page setup to default paper size, margins and orientation. More...
 
bool get_Bidi ()
 Specifies that this section contains bidirectional (complex scripts) text. More...
 
bool get_BorderAlwaysInFront ()
 Specifies where the page border is positioned relative to intersecting texts and objects. More...
 
PageBorderAppliesTo get_BorderAppliesTo ()
 Specifies which pages the page border is printed on. More...
 
PageBorderDistanceFrom get_BorderDistanceFrom ()
 Gets or sets a value that indicates whether the specified page border is measured from the edge of the page or from the text it surrounds. More...
 
SharedPtr< BorderCollectionget_Borders ()
 Gets a collection of the page borders. More...
 
bool get_BorderSurroundsFooter ()
 Specifies whether the page border includes or excludes the footer. More...
 
bool get_BorderSurroundsHeader ()
 Specifies whether the page border includes or excludes the header. More...
 
double get_BottomMargin ()
 Returns or sets the distance (in points) between the bottom edge of the page and the bottom boundary of the body text. More...
 
int32_t get_CharactersPerLine ()
 Gets or sets the number of characters per line in the document grid. More...
 
bool get_DifferentFirstPageHeaderFooter ()
 True if a different header or footer is used on the first page. More...
 
SharedPtr< EndnoteOptionsget_EndnoteOptions ()
 Provides options that control numbering and positioning of endnotes in this section. More...
 
int32_t get_FirstPageTray ()
 Gets the paper tray (bin) to use for the first page of a section. The value is implementation (printer) specific. More...
 
double get_FooterDistance ()
 Returns or sets the distance (in points) between the footer and the bottom of the page. More...
 
SharedPtr< FootnoteOptionsget_FootnoteOptions ()
 Provides options that control numbering and positioning of footnotes in this section. More...
 
double get_Gutter ()
 Gets or sets the amount of extra space added to the margin for document binding. More...
 
double get_HeaderDistance ()
 Returns or sets the distance (in points) between the header and the top of the page. More...
 
SectionLayoutMode get_LayoutMode ()
 Gets or sets the layout mode of this section. More...
 
double get_LeftMargin ()
 Returns or sets the distance (in points) between the left edge of the page and the left boundary of the body text. More...
 
int32_t get_LineNumberCountBy ()
 Returns or sets the numeric increment for line numbers. More...
 
double get_LineNumberDistanceFromText ()
 Gets or sets distance between the right edge of line numbers and the left edge of the document. More...
 
LineNumberRestartMode get_LineNumberRestartMode ()
 Gets or sets the way line numbering runs that is, whether it starts over at the beginning of a new page or section or runs continuously. More...
 
int32_t get_LinesPerPage ()
 Gets or sets the number of lines per page in the document grid. More...
 
int32_t get_LineStartingNumber ()
 Gets or sets the starting line number. More...
 
MultiplePagesType get_MultiplePages ()
 For multiple page documents, gets or sets how a document is printed or rendered so that it can be bound as a booklet. More...
 
bool get_OddAndEvenPagesHeaderFooter ()
 True if the document has different headers and footers for odd-numbered and even-numbered pages. More...
 
Orientation get_Orientation ()
 Returns or sets the orientation of the page. More...
 
int32_t get_OtherPagesTray ()
 Gets the paper tray (bin) to be used for all but the first page of a section. The value is implementation (printer) specific. More...
 
double get_PageHeight ()
 Returns or sets the height of the page in points. More...
 
NumberStyle get_PageNumberStyle ()
 Gets or sets the page number format. More...
 
int32_t get_PageStartingNumber ()
 Gets or sets the starting page number of the section. More...
 
double get_PageWidth ()
 Returns or sets the width of the page in points. More...
 
PaperSize get_PaperSize ()
 Returns or sets the paper size. More...
 
bool get_RestartPageNumbering ()
 True if page numbering restarts at the beginning of the section. More...
 
double get_RightMargin ()
 Returns or sets the distance (in points) between the right edge of the page and the right boundary of the body text. More...
 
bool get_RtlGutter ()
 Gets or sets whether Microsoft Word uses gutters for the section based on a right-to-left language or a left-to-right language. More...
 
SectionStart get_SectionStart ()
 Returns or sets the type of section break for the specified object. More...
 
int32_t get_SheetsPerBooklet ()
 Returns or sets the number of pages to be included in each booklet. More...
 
bool get_SuppressEndnotes ()
 True if endnotes are printed at the end of the next section that doesn't suppress endnotes. Suppressed endnotes are printed before the endnotes in that section. More...
 
SharedPtr< TextColumnCollectionget_TextColumns ()
 Returns a collection that represents the set of text columns. More...
 
TextOrientation get_TextOrientation ()
 Allows to specify TextOrientation for the whole page. Default value is Horizontal More...
 
double get_TopMargin ()
 Returns or sets the distance (in points) between the top edge of the page and the top boundary of the body text. More...
 
PageVerticalAlignment get_VerticalAlignment ()
 Returns or sets the vertical alignment of text on each page in a document or section. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_Bidi (bool value)
 Setter for get_Bidi. More...
 
void set_BorderAlwaysInFront (bool value)
 Setter for get_BorderAlwaysInFront. More...
 
void set_BorderAppliesTo (PageBorderAppliesTo value)
 Setter for get_BorderAppliesTo. More...
 
void set_BorderDistanceFrom (PageBorderDistanceFrom value)
 Setter for get_BorderDistanceFrom. More...
 
void set_BorderSurroundsFooter (bool value)
 Setter for get_BorderSurroundsFooter. More...
 
void set_BorderSurroundsHeader (bool value)
 Setter for get_BorderSurroundsHeader. More...
 
void set_BottomMargin (double value)
 Setter for get_BottomMargin. More...
 
void set_CharactersPerLine (int32_t value)
 Setter for get_CharactersPerLine. More...
 
void set_DifferentFirstPageHeaderFooter (bool value)
 Setter for get_DifferentFirstPageHeaderFooter. More...
 
void set_FirstPageTray (int32_t value)
 Sets the paper tray (bin) to use for the first page of a section. The value is implementation (printer) specific. More...
 
void set_FooterDistance (double value)
 Setter for get_FooterDistance. More...
 
void set_Gutter (double value)
 Setter for get_Gutter. More...
 
void set_HeaderDistance (double value)
 Setter for get_HeaderDistance. More...
 
void set_LayoutMode (SectionLayoutMode value)
 Setter for get_LayoutMode. More...
 
void set_LeftMargin (double value)
 Setter for get_LeftMargin. More...
 
void set_LineNumberCountBy (int32_t value)
 Setter for get_LineNumberCountBy. More...
 
void set_LineNumberDistanceFromText (double value)
 Setter for get_LineNumberDistanceFromText. More...
 
void set_LineNumberRestartMode (LineNumberRestartMode value)
 Setter for get_LineNumberRestartMode. More...
 
void set_LinesPerPage (int32_t value)
 Setter for get_LinesPerPage. More...
 
void set_LineStartingNumber (int32_t value)
 Setter for get_LineStartingNumber. More...
 
void set_MultiplePages (MultiplePagesType value)
 Setter for get_MultiplePages. More...
 
void set_OddAndEvenPagesHeaderFooter (bool value)
 Setter for get_OddAndEvenPagesHeaderFooter. More...
 
void set_Orientation (Orientation value)
 Setter for get_Orientation. More...
 
void set_OtherPagesTray (int32_t value)
 Sets the paper tray (bin) to be used for all but the first page of a section. The value is implementation (printer) specific. More...
 
void set_PageHeight (double value)
 Setter for get_PageHeight. More...
 
void set_PageNumberStyle (NumberStyle value)
 Setter for get_PageNumberStyle. More...
 
void set_PageStartingNumber (int32_t value)
 Setter for get_PageStartingNumber. More...
 
void set_PageWidth (double value)
 Setter for get_PageWidth. More...
 
void set_PaperSize (PaperSize value)
 Setter for get_PaperSize. More...
 
void set_RestartPageNumbering (bool value)
 Setter for get_RestartPageNumbering. More...
 
void set_RightMargin (double value)
 Setter for get_RightMargin. More...
 
void set_RtlGutter (bool value)
 Setter for get_RtlGutter. More...
 
void set_SectionStart (SectionStart value)
 Setter for get_SectionStart. More...
 
void set_SheetsPerBooklet (int32_t value)
 Setter for get_SheetsPerBooklet. More...
 
void set_SuppressEndnotes (bool value)
 Setter for get_SuppressEndnotes. More...
 
void set_TextOrientation (TextOrientation value)
 Setter for get_TextOrientation. More...
 
void set_TopMargin (double value)
 Setter for get_TopMargin. More...
 
void set_VerticalAlignment (PageVerticalAlignment value)
 Setter for get_VerticalAlignment. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ ClearFormatting()

void Aspose::Words::PageSetup::ClearFormatting ( )

Resets page setup to default paper size, margins and orientation.

Examples

Shows how to apply and revert page setup settings to sections in a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Modify the page setup properties for the builder's current section and add text.
builder->get_PageSetup()->set_Orientation(Orientation::Landscape);
builder->get_PageSetup()->set_VerticalAlignment(PageVerticalAlignment::Center);
builder->Writeln(u"This is the first section, which landscape oriented with vertically centered text.");
// If we start a new section using a document builder,
// it will inherit the builder's current page setup properties.
builder->InsertBreak(BreakType::SectionBreakNewPage);
ASSERT_EQ(Orientation::Landscape, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_Orientation());
ASSERT_EQ(PageVerticalAlignment::Center, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_VerticalAlignment());
// We can revert its page setup properties to their default values using the "ClearFormatting" method.
builder->get_PageSetup()->ClearFormatting();
ASSERT_EQ(Orientation::Portrait, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_Orientation());
ASSERT_EQ(PageVerticalAlignment::Top, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_VerticalAlignment());
builder->Writeln(u"This is the second section, which is in default Letter paper size, portrait orientation and top alignment.");
doc->Save(ArtifactsDir + u"PageSetup.ClearFormatting.docx");

◆ get_Bidi()

bool Aspose::Words::PageSetup::get_Bidi ( )

Specifies that this section contains bidirectional (complex scripts) text.

When true, the columns in this section are laid out from right to left.

Examples

Shows how to set the order of text columns in a section.

auto doc = MakeObject<Document>();
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->get_TextColumns()->SetCount(3);
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Write(u"Column 1.");
builder->InsertBreak(BreakType::ColumnBreak);
builder->Write(u"Column 2.");
builder->InsertBreak(BreakType::ColumnBreak);
builder->Write(u"Column 3.");
// Set the "Bidi" property to "true" to arrange the columns starting from the page's right side.
// The order of the columns will match the direction of the right-to-left text.
// Set the "Bidi" property to "false" to arrange the columns starting from the page's left side.
// The order of the columns will match the direction of the left-to-right text.
pageSetup->set_Bidi(reverseColumns);
doc->Save(ArtifactsDir + u"PageSetup.Bidi.docx");

◆ get_BorderAlwaysInFront()

bool Aspose::Words::PageSetup::get_BorderAlwaysInFront ( )

Specifies where the page border is positioned relative to intersecting texts and objects.

Examples

Shows how to create a wide blue band border at the top of the first page.

auto doc = MakeObject<Document>();
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->set_BorderAlwaysInFront(false);
pageSetup->set_BorderDistanceFrom(PageBorderDistanceFrom::PageEdge);
pageSetup->set_BorderAppliesTo(PageBorderAppliesTo::FirstPage);
SharedPtr<Border> border = pageSetup->get_Borders()->idx_get(BorderType::Top);
border->set_LineStyle(LineStyle::Single);
border->set_LineWidth(30);
border->set_Color(System::Drawing::Color::get_Blue());
border->set_DistanceFromText(0);
doc->Save(ArtifactsDir + u"PageSetup.PageBorderProperties.docx");

◆ get_BorderAppliesTo()

Aspose::Words::PageBorderAppliesTo Aspose::Words::PageSetup::get_BorderAppliesTo ( )

Specifies which pages the page border is printed on.

Examples

Shows how to create a wide blue band border at the top of the first page.

auto doc = MakeObject<Document>();
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->set_BorderAlwaysInFront(false);
pageSetup->set_BorderDistanceFrom(PageBorderDistanceFrom::PageEdge);
pageSetup->set_BorderAppliesTo(PageBorderAppliesTo::FirstPage);
SharedPtr<Border> border = pageSetup->get_Borders()->idx_get(BorderType::Top);
border->set_LineStyle(LineStyle::Single);
border->set_LineWidth(30);
border->set_Color(System::Drawing::Color::get_Blue());
border->set_DistanceFromText(0);
doc->Save(ArtifactsDir + u"PageSetup.PageBorderProperties.docx");

◆ get_BorderDistanceFrom()

Aspose::Words::PageBorderDistanceFrom Aspose::Words::PageSetup::get_BorderDistanceFrom ( )

Gets or sets a value that indicates whether the specified page border is measured from the edge of the page or from the text it surrounds.

Examples

Shows how to create a wide blue band border at the top of the first page.

auto doc = MakeObject<Document>();
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->set_BorderAlwaysInFront(false);
pageSetup->set_BorderDistanceFrom(PageBorderDistanceFrom::PageEdge);
pageSetup->set_BorderAppliesTo(PageBorderAppliesTo::FirstPage);
SharedPtr<Border> border = pageSetup->get_Borders()->idx_get(BorderType::Top);
border->set_LineStyle(LineStyle::Single);
border->set_LineWidth(30);
border->set_Color(System::Drawing::Color::get_Blue());
border->set_DistanceFromText(0);
doc->Save(ArtifactsDir + u"PageSetup.PageBorderProperties.docx");

◆ get_Borders()

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

Gets a collection of the page borders.

Examples

Shows how to create green wavy page border with a shadow.

auto doc = MakeObject<Document>();
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->get_Borders()->set_LineStyle(LineStyle::DoubleWave);
pageSetup->get_Borders()->set_LineWidth(2);
pageSetup->get_Borders()->set_Color(System::Drawing::Color::get_Green());
pageSetup->get_Borders()->set_DistanceFromText(24);
pageSetup->get_Borders()->set_Shadow(true);
doc->Save(ArtifactsDir + u"PageSetup.PageBorders.docx");

◆ get_BorderSurroundsFooter()

bool Aspose::Words::PageSetup::get_BorderSurroundsFooter ( )

Specifies whether the page border includes or excludes the footer.

Examples

Shows how to apply a border to the page and header/footer.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello world! This is the main body text.");
builder->MoveToHeaderFooter(HeaderFooterType::HeaderPrimary);
builder->Write(u"This is the header.");
builder->MoveToHeaderFooter(HeaderFooterType::FooterPrimary);
builder->Write(u"This is the footer.");
builder->MoveToDocumentEnd();
// Insert a blue double-line border.
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->get_Borders()->set_LineStyle(LineStyle::Double);
pageSetup->get_Borders()->set_Color(System::Drawing::Color::get_Blue());
// A section's PageSetup object has "BorderSurroundsHeader" and "BorderSurroundsFooter" flags that determine
// whether a page border surrounds the main body text, also includes the header or footer, respectively.
// Set the "BorderSurroundsHeader" flag to "true" to surround the header with our border,
// and then set the "BorderSurroundsFooter" flag to leave the footer outside of the border.
pageSetup->set_BorderSurroundsHeader(true);
pageSetup->set_BorderSurroundsFooter(false);
doc->Save(ArtifactsDir + u"PageSetup.PageBorder.docx");

◆ get_BorderSurroundsHeader()

bool Aspose::Words::PageSetup::get_BorderSurroundsHeader ( )

Specifies whether the page border includes or excludes the header.

Examples

Shows how to apply a border to the page and header/footer.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello world! This is the main body text.");
builder->MoveToHeaderFooter(HeaderFooterType::HeaderPrimary);
builder->Write(u"This is the header.");
builder->MoveToHeaderFooter(HeaderFooterType::FooterPrimary);
builder->Write(u"This is the footer.");
builder->MoveToDocumentEnd();
// Insert a blue double-line border.
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->get_Borders()->set_LineStyle(LineStyle::Double);
pageSetup->get_Borders()->set_Color(System::Drawing::Color::get_Blue());
// A section's PageSetup object has "BorderSurroundsHeader" and "BorderSurroundsFooter" flags that determine
// whether a page border surrounds the main body text, also includes the header or footer, respectively.
// Set the "BorderSurroundsHeader" flag to "true" to surround the header with our border,
// and then set the "BorderSurroundsFooter" flag to leave the footer outside of the border.
pageSetup->set_BorderSurroundsHeader(true);
pageSetup->set_BorderSurroundsFooter(false);
doc->Save(ArtifactsDir + u"PageSetup.PageBorder.docx");

◆ get_BottomMargin()

double Aspose::Words::PageSetup::get_BottomMargin ( )

Returns or sets the distance (in points) between the bottom edge of the page and the bottom boundary of the body text.

Examples

Shows how to adjust paper size, orientation, margins, along with other settings for a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_PageSetup()->set_PaperSize(PaperSize::Legal);
builder->get_PageSetup()->set_Orientation(Orientation::Landscape);
builder->get_PageSetup()->set_TopMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_BottomMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_LeftMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_RightMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_HeaderDistance(ConvertUtil::InchToPoint(0.2));
builder->get_PageSetup()->set_FooterDistance(ConvertUtil::InchToPoint(0.2));
builder->Writeln(u"Hello world!");
doc->Save(ArtifactsDir + u"PageSetup.PageMargins.docx");

◆ get_CharactersPerLine()

int32_t Aspose::Words::PageSetup::get_CharactersPerLine ( )

Gets or sets the number of characters per line in the document grid.

Minimum value of the property is 1. Maximum value depends on page width and font size of the Normal style. Minimum character pitch is 90 percent of the font size. For example, maximum number of characters per line of a Letter page with one-inch margins is 43.

By default, the property has a value, on which character pitch equals to font size of the Normal style.

Examples

Shows how to specify a for the number of characters that each line may have.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Enable pitching, and then use it to set the number of characters per line in this section.
builder->get_PageSetup()->set_LayoutMode(SectionLayoutMode::Grid);
builder->get_PageSetup()->set_CharactersPerLine(10);
// The number of characters also depends on the size of the font.
doc->get_Styles()->idx_get(u"Normal")->get_Font()->set_Size(20);
ASSERT_EQ(8, doc->get_FirstSection()->get_PageSetup()->get_CharactersPerLine());
builder->Writeln(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.CharactersPerLine.docx");

◆ get_DifferentFirstPageHeaderFooter()

bool Aspose::Words::PageSetup::get_DifferentFirstPageHeaderFooter ( )

True if a different header or footer is used on the first page.

Examples

Shows how to create headers and footers in a document using DocumentBuilder.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Specify that we want different headers and footers for first, even and odd pages.
builder->get_PageSetup()->set_DifferentFirstPageHeaderFooter(true);
builder->get_PageSetup()->set_OddAndEvenPagesHeaderFooter(true);
// Create the headers, then add three pages to the document to display each header type.
builder->MoveToHeaderFooter(HeaderFooterType::HeaderFirst);
builder->Write(u"Header for the first page");
builder->MoveToHeaderFooter(HeaderFooterType::HeaderEven);
builder->Write(u"Header for even pages");
builder->MoveToHeaderFooter(HeaderFooterType::HeaderPrimary);
builder->Write(u"Header for all other pages");
builder->MoveToSection(0);
builder->Writeln(u"Page1");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Page2");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Page3");
doc->Save(ArtifactsDir + u"DocumentBuilder.HeadersAndFooters.docx");

Shows how to track the order in which a text replacement operation traverses nodes.

void Order(bool differentFirstPageHeaderFooter)
{
auto doc = MakeObject<Document>(MyDir + u"Header and footer types.docx");
SharedPtr<Section> firstPageSection = doc->get_FirstSection();
auto logger = MakeObject<ExHeaderFooter::ReplaceLog>();
auto options = MakeObject<FindReplaceOptions>();
options->set_ReplacingCallback(logger);
// Using a different header/footer for the first page will affect the search order.
firstPageSection->get_PageSetup()->set_DifferentFirstPageHeaderFooter(differentFirstPageHeaderFooter);
doc->get_Range()->Replace(MakeObject<System::Text::RegularExpressions::Regex>(u"(header|footer)"), u"", options);
if (differentFirstPageHeaderFooter)
{
ASSERT_EQ(u"First header\nFirst footer\nSecond header\nSecond footer\nThird header\nThird footer\n", logger->get_Text().Replace(u"\r", u""));
}
else
{
ASSERT_EQ(u"Third header\nFirst header\nThird footer\nFirst footer\nSecond header\nSecond footer\n", logger->get_Text().Replace(u"\r", u""));
}
}
class ReplaceLog : public IReplacingCallback
{
public:
String get_Text()
{
return mTextBuilder->ToString();
}
ReplaceAction Replacing(SharedPtr<ReplacingArgs> args) override
{
mTextBuilder->AppendLine(args->get_MatchNode()->GetText());
return ReplaceAction::Skip;
}
ReplaceLog() : mTextBuilder(MakeObject<System::Text::StringBuilder>())
{
}
private:
SharedPtr<System::Text::StringBuilder> mTextBuilder;
};

Shows how to enable or disable primary headers/footers.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Below are two types of header/footers.
// 1 - The "First" header/footer, which appears on the first page of the section.
builder->MoveToHeaderFooter(HeaderFooterType::HeaderFirst);
builder->Writeln(u"First page header.");
builder->MoveToHeaderFooter(HeaderFooterType::FooterFirst);
builder->Writeln(u"First page footer.");
// 2 - The "Primary" header/footer, which appears on every page in the section.
// We can override the primary header/footer by a first and an even page header/footer.
builder->MoveToHeaderFooter(HeaderFooterType::HeaderPrimary);
builder->Writeln(u"Primary header.");
builder->MoveToHeaderFooter(HeaderFooterType::FooterPrimary);
builder->Writeln(u"Primary footer.");
builder->MoveToSection(0);
builder->Writeln(u"Page 1.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Page 2.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Page 3.");
// Each section has a "PageSetup" object that specifies page appearance-related properties
// such as orientation, size, and borders.
// Set the "DifferentFirstPageHeaderFooter" property to "true" to apply the first header/footer to the first page.
// Set the "DifferentFirstPageHeaderFooter" property to "false"
// to make the first page display the primary header/footer.
builder->get_PageSetup()->set_DifferentFirstPageHeaderFooter(differentFirstPageHeaderFooter);
doc->Save(ArtifactsDir + u"PageSetup.DifferentFirstPageHeaderFooter.docx");

◆ get_EndnoteOptions()

System::SharedPtr<Aspose::Words::Notes::EndnoteOptions> Aspose::Words::PageSetup::get_EndnoteOptions ( )

Provides options that control numbering and positioning of endnotes in this section.

Examples

Shows how to configure options affecting footnotes/endnotes in a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Write(u"Hello world!");
builder->InsertFootnote(FootnoteType::Footnote, u"Footnote reference text.");
// Configure all footnotes in the first section to restart the numbering from 1
// at each new page and display themselves directly beneath the text on every page.
SharedPtr<FootnoteOptions> footnoteOptions = doc->get_Sections()->idx_get(0)->get_PageSetup()->get_FootnoteOptions();
footnoteOptions->set_Position(FootnotePosition::BeneathText);
footnoteOptions->set_RestartRule(FootnoteNumberingRule::RestartPage);
footnoteOptions->set_StartNumber(1);
builder->Write(u" Hello again.");
builder->InsertFootnote(FootnoteType::Footnote, u"Endnote reference text.");
// Configure all endnotes in the first section to maintain a continuous count throughout the section,
// starting from 1. Also, set them all to appear collected at the end of the document.
SharedPtr<EndnoteOptions> endnoteOptions = doc->get_Sections()->idx_get(0)->get_PageSetup()->get_EndnoteOptions();
endnoteOptions->set_Position(EndnotePosition::EndOfDocument);
endnoteOptions->set_RestartRule(FootnoteNumberingRule::Continuous);
endnoteOptions->set_StartNumber(1);
doc->Save(ArtifactsDir + u"PageSetup.FootnoteOptions.docx");

◆ get_FirstPageTray()

int32_t Aspose::Words::PageSetup::get_FirstPageTray ( )

Gets the paper tray (bin) to use for the first page of a section. The value is implementation (printer) specific.

◆ get_FooterDistance()

double Aspose::Words::PageSetup::get_FooterDistance ( )

Returns or sets the distance (in points) between the footer and the bottom of the page.

Examples

Shows how to adjust paper size, orientation, margins, along with other settings for a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_PageSetup()->set_PaperSize(PaperSize::Legal);
builder->get_PageSetup()->set_Orientation(Orientation::Landscape);
builder->get_PageSetup()->set_TopMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_BottomMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_LeftMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_RightMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_HeaderDistance(ConvertUtil::InchToPoint(0.2));
builder->get_PageSetup()->set_FooterDistance(ConvertUtil::InchToPoint(0.2));
builder->Writeln(u"Hello world!");
doc->Save(ArtifactsDir + u"PageSetup.PageMargins.docx");

◆ get_FootnoteOptions()

System::SharedPtr<Aspose::Words::Notes::FootnoteOptions> Aspose::Words::PageSetup::get_FootnoteOptions ( )

Provides options that control numbering and positioning of footnotes in this section.

Examples

Shows how to configure options affecting footnotes/endnotes in a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Write(u"Hello world!");
builder->InsertFootnote(FootnoteType::Footnote, u"Footnote reference text.");
// Configure all footnotes in the first section to restart the numbering from 1
// at each new page and display themselves directly beneath the text on every page.
SharedPtr<FootnoteOptions> footnoteOptions = doc->get_Sections()->idx_get(0)->get_PageSetup()->get_FootnoteOptions();
footnoteOptions->set_Position(FootnotePosition::BeneathText);
footnoteOptions->set_RestartRule(FootnoteNumberingRule::RestartPage);
footnoteOptions->set_StartNumber(1);
builder->Write(u" Hello again.");
builder->InsertFootnote(FootnoteType::Footnote, u"Endnote reference text.");
// Configure all endnotes in the first section to maintain a continuous count throughout the section,
// starting from 1. Also, set them all to appear collected at the end of the document.
SharedPtr<EndnoteOptions> endnoteOptions = doc->get_Sections()->idx_get(0)->get_PageSetup()->get_EndnoteOptions();
endnoteOptions->set_Position(EndnotePosition::EndOfDocument);
endnoteOptions->set_RestartRule(FootnoteNumberingRule::Continuous);
endnoteOptions->set_StartNumber(1);
doc->Save(ArtifactsDir + u"PageSetup.FootnoteOptions.docx");

◆ get_Gutter()

double Aspose::Words::PageSetup::get_Gutter ( )

Gets or sets the amount of extra space added to the margin for document binding.

Examples

Shows how to set gutter margins.

auto doc = MakeObject<Document>();
// Insert text that spans several pages.
auto builder = MakeObject<DocumentBuilder>(doc);
for (int i = 0; i < 6; i++)
{
builder->Write(String(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, ") +
u"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
builder->InsertBreak(BreakType::PageBreak);
}
// A gutter adds whitespaces to either the left or right page margin,
// which makes up for the center folding of pages in a book encroaching on the page's layout.
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
// Determine how much space our pages have for text within the margins and then add an amount to pad a margin.
ASSERT_NEAR(470.30, pageSetup->get_PageWidth() - pageSetup->get_LeftMargin() - pageSetup->get_RightMargin(), 0.01);
pageSetup->set_Gutter(100.0);
// Set the "RtlGutter" property to "true" to place the gutter in a more suitable position for right-to-left text.
pageSetup->set_RtlGutter(true);
// Set the "MultiplePages" property to "MultiplePagesType.MirrorMargins" to alternate
// the left/right page side position of margins every page.
pageSetup->set_MultiplePages(MultiplePagesType::MirrorMargins);
doc->Save(ArtifactsDir + u"PageSetup.Gutter.docx");

Shows how to configure a document that can be printed as a book fold.

auto doc = MakeObject<Document>();
// Insert text that spans 16 pages.
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"My Booklet:");
for (int i = 0; i < 15; i++)
{
builder->InsertBreak(BreakType::PageBreak);
builder->Write(String::Format(u"Booklet face #{0}", i));
}
// Configure the first section's "PageSetup" property to print the document in the form of a book fold.
// When we print this document on both sides, we can take the pages to stack them
// and fold them all down the middle at once. The contents of the document will line up into a book fold.
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->set_MultiplePages(MultiplePagesType::BookFoldPrinting);
// We can only specify the number of sheets in multiples of 4.
pageSetup->set_SheetsPerBooklet(4);
doc->Save(ArtifactsDir + u"PageSetup.Booklet.docx");

◆ get_HeaderDistance()

double Aspose::Words::PageSetup::get_HeaderDistance ( )

Returns or sets the distance (in points) between the header and the top of the page.

Examples

Shows how to adjust paper size, orientation, margins, along with other settings for a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_PageSetup()->set_PaperSize(PaperSize::Legal);
builder->get_PageSetup()->set_Orientation(Orientation::Landscape);
builder->get_PageSetup()->set_TopMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_BottomMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_LeftMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_RightMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_HeaderDistance(ConvertUtil::InchToPoint(0.2));
builder->get_PageSetup()->set_FooterDistance(ConvertUtil::InchToPoint(0.2));
builder->Writeln(u"Hello world!");
doc->Save(ArtifactsDir + u"PageSetup.PageMargins.docx");

◆ get_LayoutMode()

Aspose::Words::SectionLayoutMode Aspose::Words::PageSetup::get_LayoutMode ( )

Gets or sets the layout mode of this section.

Examples

Shows how to specify a for the number of characters that each line may have.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Enable pitching, and then use it to set the number of characters per line in this section.
builder->get_PageSetup()->set_LayoutMode(SectionLayoutMode::Grid);
builder->get_PageSetup()->set_CharactersPerLine(10);
// The number of characters also depends on the size of the font.
doc->get_Styles()->idx_get(u"Normal")->get_Font()->set_Size(20);
ASSERT_EQ(8, doc->get_FirstSection()->get_PageSetup()->get_CharactersPerLine());
builder->Writeln(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.CharactersPerLine.docx");

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_LeftMargin()

double Aspose::Words::PageSetup::get_LeftMargin ( )

Returns or sets the distance (in points) between the left edge of the page and the left boundary of the body text.

Examples

Shows how to adjust paper size, orientation, margins, along with other settings for a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_PageSetup()->set_PaperSize(PaperSize::Legal);
builder->get_PageSetup()->set_Orientation(Orientation::Landscape);
builder->get_PageSetup()->set_TopMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_BottomMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_LeftMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_RightMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_HeaderDistance(ConvertUtil::InchToPoint(0.2));
builder->get_PageSetup()->set_FooterDistance(ConvertUtil::InchToPoint(0.2));
builder->Writeln(u"Hello world!");
doc->Save(ArtifactsDir + u"PageSetup.PageMargins.docx");

◆ get_LineNumberCountBy()

int32_t Aspose::Words::PageSetup::get_LineNumberCountBy ( )

Returns or sets the numeric increment for line numbers.

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_LineNumberDistanceFromText()

double Aspose::Words::PageSetup::get_LineNumberDistanceFromText ( )

Gets or sets distance between the right edge of line numbers and the left edge of the document.

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_LineNumberRestartMode()

Aspose::Words::LineNumberRestartMode Aspose::Words::PageSetup::get_LineNumberRestartMode ( )

Gets or sets the way line numbering runs that is, whether it starts over at the beginning of a new page or section or runs continuously.

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_LinesPerPage()

int32_t Aspose::Words::PageSetup::get_LinesPerPage ( )

Gets or sets the number of lines per page in the document grid.

Minimum value of the property is 1. Maximum value depends on page height and font size of the Normal style. Minimum line pitch is 136 percent of the font size. For example, maximum number of lines per page of a Letter page with one-inch margins is 39.

By default, the property has a value, on which line pitch is in 1.5 times greater than font size of the Normal style.

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_LineStartingNumber()

int32_t Aspose::Words::PageSetup::get_LineStartingNumber ( )

Gets or sets the starting line number.

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_MultiplePages()

Aspose::Words::Settings::MultiplePagesType Aspose::Words::PageSetup::get_MultiplePages ( )

For multiple page documents, gets or sets how a document is printed or rendered so that it can be bound as a booklet.

Examples

Shows how to set gutter margins.

auto doc = MakeObject<Document>();
// Insert text that spans several pages.
auto builder = MakeObject<DocumentBuilder>(doc);
for (int i = 0; i < 6; i++)
{
builder->Write(String(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, ") +
u"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
builder->InsertBreak(BreakType::PageBreak);
}
// A gutter adds whitespaces to either the left or right page margin,
// which makes up for the center folding of pages in a book encroaching on the page's layout.
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
// Determine how much space our pages have for text within the margins and then add an amount to pad a margin.
ASSERT_NEAR(470.30, pageSetup->get_PageWidth() - pageSetup->get_LeftMargin() - pageSetup->get_RightMargin(), 0.01);
pageSetup->set_Gutter(100.0);
// Set the "RtlGutter" property to "true" to place the gutter in a more suitable position for right-to-left text.
pageSetup->set_RtlGutter(true);
// Set the "MultiplePages" property to "MultiplePagesType.MirrorMargins" to alternate
// the left/right page side position of margins every page.
pageSetup->set_MultiplePages(MultiplePagesType::MirrorMargins);
doc->Save(ArtifactsDir + u"PageSetup.Gutter.docx");

Shows how to configure a document that can be printed as a book fold.

auto doc = MakeObject<Document>();
// Insert text that spans 16 pages.
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"My Booklet:");
for (int i = 0; i < 15; i++)
{
builder->InsertBreak(BreakType::PageBreak);
builder->Write(String::Format(u"Booklet face #{0}", i));
}
// Configure the first section's "PageSetup" property to print the document in the form of a book fold.
// When we print this document on both sides, we can take the pages to stack them
// and fold them all down the middle at once. The contents of the document will line up into a book fold.
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->set_MultiplePages(MultiplePagesType::BookFoldPrinting);
// We can only specify the number of sheets in multiples of 4.
pageSetup->set_SheetsPerBooklet(4);
doc->Save(ArtifactsDir + u"PageSetup.Booklet.docx");

◆ get_OddAndEvenPagesHeaderFooter()

bool Aspose::Words::PageSetup::get_OddAndEvenPagesHeaderFooter ( )

True if the document has different headers and footers for odd-numbered and even-numbered pages.

Examples

Shows how to create headers and footers in a document using DocumentBuilder.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Specify that we want different headers and footers for first, even and odd pages.
builder->get_PageSetup()->set_DifferentFirstPageHeaderFooter(true);
builder->get_PageSetup()->set_OddAndEvenPagesHeaderFooter(true);
// Create the headers, then add three pages to the document to display each header type.
builder->MoveToHeaderFooter(HeaderFooterType::HeaderFirst);
builder->Write(u"Header for the first page");
builder->MoveToHeaderFooter(HeaderFooterType::HeaderEven);
builder->Write(u"Header for even pages");
builder->MoveToHeaderFooter(HeaderFooterType::HeaderPrimary);
builder->Write(u"Header for all other pages");
builder->MoveToSection(0);
builder->Writeln(u"Page1");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Page2");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Page3");
doc->Save(ArtifactsDir + u"DocumentBuilder.HeadersAndFooters.docx");

Shows how to enable or disable even page headers/footers.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Below are two types of header/footers.
// 1 - The "Primary" header/footer, which appears on every page in the section.
// We can override the primary header/footer by a first and an even page header/footer.
builder->MoveToHeaderFooter(HeaderFooterType::HeaderPrimary);
builder->Writeln(u"Primary header.");
builder->MoveToHeaderFooter(HeaderFooterType::FooterPrimary);
builder->Writeln(u"Primary footer.");
// 2 - The "Even" header/footer, which appears on every even page of this section.
builder->MoveToHeaderFooter(HeaderFooterType::HeaderEven);
builder->Writeln(u"Even page header.");
builder->MoveToHeaderFooter(HeaderFooterType::FooterEven);
builder->Writeln(u"Even page footer.");
builder->MoveToSection(0);
builder->Writeln(u"Page 1.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Page 2.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Page 3.");
// Each section has a "PageSetup" object that specifies page appearance-related properties
// such as orientation, size, and borders.
// Set the "OddAndEvenPagesHeaderFooter" property to "true"
// to display the even page header/footer on even pages.
// Set the "OddAndEvenPagesHeaderFooter" property to "false"
// to display the primary header/footer on even pages.
builder->get_PageSetup()->set_OddAndEvenPagesHeaderFooter(oddAndEvenPagesHeaderFooter);
doc->Save(ArtifactsDir + u"PageSetup.OddAndEvenPagesHeaderFooter.docx");

◆ get_Orientation()

Aspose::Words::Orientation Aspose::Words::PageSetup::get_Orientation ( )

Returns or sets the orientation of the page.

Changing Orientation swaps PageWidth and PageHeight.

Examples

Shows how to apply and revert page setup settings to sections in a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Modify the page setup properties for the builder's current section and add text.
builder->get_PageSetup()->set_Orientation(Orientation::Landscape);
builder->get_PageSetup()->set_VerticalAlignment(PageVerticalAlignment::Center);
builder->Writeln(u"This is the first section, which landscape oriented with vertically centered text.");
// If we start a new section using a document builder,
// it will inherit the builder's current page setup properties.
builder->InsertBreak(BreakType::SectionBreakNewPage);
ASSERT_EQ(Orientation::Landscape, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_Orientation());
ASSERT_EQ(PageVerticalAlignment::Center, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_VerticalAlignment());
// We can revert its page setup properties to their default values using the "ClearFormatting" method.
builder->get_PageSetup()->ClearFormatting();
ASSERT_EQ(Orientation::Portrait, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_Orientation());
ASSERT_EQ(PageVerticalAlignment::Top, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_VerticalAlignment());
builder->Writeln(u"This is the second section, which is in default Letter paper size, portrait orientation and top alignment.");
doc->Save(ArtifactsDir + u"PageSetup.ClearFormatting.docx");

Shows how to adjust paper size, orientation, margins, along with other settings for a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_PageSetup()->set_PaperSize(PaperSize::Legal);
builder->get_PageSetup()->set_Orientation(Orientation::Landscape);
builder->get_PageSetup()->set_TopMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_BottomMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_LeftMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_RightMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_HeaderDistance(ConvertUtil::InchToPoint(0.2));
builder->get_PageSetup()->set_FooterDistance(ConvertUtil::InchToPoint(0.2));
builder->Writeln(u"Hello world!");
doc->Save(ArtifactsDir + u"PageSetup.PageMargins.docx");

◆ get_OtherPagesTray()

int32_t Aspose::Words::PageSetup::get_OtherPagesTray ( )

Gets the paper tray (bin) to be used for all but the first page of a section. The value is implementation (printer) specific.

◆ get_PageHeight()

double Aspose::Words::PageSetup::get_PageHeight ( )

Returns or sets the height of the page in points.

Examples

Shows how to insert an image, and use it as a watermark.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert the image into the header so that it will be visible on every page.
SharedPtr<System::Drawing::Image> image = System::Drawing::Image::FromFile(ImageDir + u"Transparent background logo.png");
builder->MoveToHeaderFooter(HeaderFooterType::HeaderPrimary);
SharedPtr<Shape> shape = builder->InsertImage(image);
shape->set_WrapType(WrapType::None);
shape->set_BehindText(true);
// Place the image at the center of the page.
shape->set_RelativeHorizontalPosition(RelativeHorizontalPosition::Page);
shape->set_RelativeVerticalPosition(RelativeVerticalPosition::Page);
shape->set_Left((builder->get_PageSetup()->get_PageWidth() - shape->get_Width()) / 2);
shape->set_Top((builder->get_PageSetup()->get_PageHeight() - shape->get_Height()) / 2);
doc->Save(ArtifactsDir + u"DocumentBuilder.InsertWatermark.docx");

◆ get_PageNumberStyle()

Aspose::Words::NumberStyle Aspose::Words::PageSetup::get_PageNumberStyle ( )

Gets or sets the page number format.

Examples

Shows how to set up page numbering in a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Section 1, page 1.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Section 1, page 2.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Section 1, page 3.");
builder->InsertBreak(BreakType::SectionBreakNewPage);
builder->Writeln(u"Section 2, page 1.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Section 2, page 2.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Section 2, page 3.");
// Move the document builder to the first section's primary header,
// which every page in that section will display.
builder->MoveToSection(0);
builder->MoveToHeaderFooter(HeaderFooterType::HeaderPrimary);
// Insert a PAGE field, which will display the number of the current page.
builder->Write(u"Page ");
builder->InsertField(u"PAGE", u"");
// Configure the section to have the page count that PAGE fields display start from 5.
// Also, configure all PAGE fields to display their page numbers using uppercase Roman numerals.
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->set_RestartPageNumbering(true);
pageSetup->set_PageStartingNumber(5);
pageSetup->set_PageNumberStyle(NumberStyle::UppercaseRoman);
// Create another primary header for the second section, with another PAGE field.
builder->MoveToSection(1);
builder->MoveToHeaderFooter(HeaderFooterType::HeaderPrimary);
builder->get_ParagraphFormat()->set_Alignment(ParagraphAlignment::Center);
builder->Write(u" - ");
builder->InsertField(u"PAGE", u"");
builder->Write(u" - ");
// Configure the section to have the page count that PAGE fields display start from 10.
// Also, configure all PAGE fields to display their page numbers using Arabic numbers.
pageSetup = doc->get_Sections()->idx_get(1)->get_PageSetup();
pageSetup->set_PageStartingNumber(10);
pageSetup->set_RestartPageNumbering(true);
pageSetup->set_PageNumberStyle(NumberStyle::Arabic);
doc->Save(ArtifactsDir + u"PageSetup.PageNumbering.docx");

◆ get_PageStartingNumber()

int32_t Aspose::Words::PageSetup::get_PageStartingNumber ( )

Gets or sets the starting page number of the section.

Examples

Shows how to set up page numbering in a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Section 1, page 1.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Section 1, page 2.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Section 1, page 3.");
builder->InsertBreak(BreakType::SectionBreakNewPage);
builder->Writeln(u"Section 2, page 1.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Section 2, page 2.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Section 2, page 3.");
// Move the document builder to the first section's primary header,
// which every page in that section will display.
builder->MoveToSection(0);
builder->MoveToHeaderFooter(HeaderFooterType::HeaderPrimary);
// Insert a PAGE field, which will display the number of the current page.
builder->Write(u"Page ");
builder->InsertField(u"PAGE", u"");
// Configure the section to have the page count that PAGE fields display start from 5.
// Also, configure all PAGE fields to display their page numbers using uppercase Roman numerals.
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->set_RestartPageNumbering(true);
pageSetup->set_PageStartingNumber(5);
pageSetup->set_PageNumberStyle(NumberStyle::UppercaseRoman);
// Create another primary header for the second section, with another PAGE field.
builder->MoveToSection(1);
builder->MoveToHeaderFooter(HeaderFooterType::HeaderPrimary);
builder->get_ParagraphFormat()->set_Alignment(ParagraphAlignment::Center);
builder->Write(u" - ");
builder->InsertField(u"PAGE", u"");
builder->Write(u" - ");
// Configure the section to have the page count that PAGE fields display start from 10.
// Also, configure all PAGE fields to display their page numbers using Arabic numbers.
pageSetup = doc->get_Sections()->idx_get(1)->get_PageSetup();
pageSetup->set_PageStartingNumber(10);
pageSetup->set_RestartPageNumbering(true);
pageSetup->set_PageNumberStyle(NumberStyle::Arabic);
doc->Save(ArtifactsDir + u"PageSetup.PageNumbering.docx");

◆ get_PageWidth()

double Aspose::Words::PageSetup::get_PageWidth ( )

Returns or sets the width of the page in points.

Examples

Shows how to insert an image, and use it as a watermark.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert the image into the header so that it will be visible on every page.
SharedPtr<System::Drawing::Image> image = System::Drawing::Image::FromFile(ImageDir + u"Transparent background logo.png");
builder->MoveToHeaderFooter(HeaderFooterType::HeaderPrimary);
SharedPtr<Shape> shape = builder->InsertImage(image);
shape->set_WrapType(WrapType::None);
shape->set_BehindText(true);
// Place the image at the center of the page.
shape->set_RelativeHorizontalPosition(RelativeHorizontalPosition::Page);
shape->set_RelativeVerticalPosition(RelativeVerticalPosition::Page);
shape->set_Left((builder->get_PageSetup()->get_PageWidth() - shape->get_Width()) / 2);
shape->set_Top((builder->get_PageSetup()->get_PageHeight() - shape->get_Height()) / 2);
doc->Save(ArtifactsDir + u"DocumentBuilder.InsertWatermark.docx");

Shows how to insert a floating image, and specify its position and size.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
shape->set_WrapType(WrapType::None);
// Configure the shape's "RelativeHorizontalPosition" property to treat the value of the "Left" property
// as the shape's horizontal distance, in points, from the left side of the page.
shape->set_RelativeHorizontalPosition(RelativeHorizontalPosition::Page);
// Set the shape's horizontal distance from the left side of the page to 100.
shape->set_Left(100);
// Use the "RelativeVerticalPosition" property in a similar way to position the shape 80pt below the top of the page.
shape->set_RelativeVerticalPosition(RelativeVerticalPosition::Page);
shape->set_Top(80);
// Set the shape's height, which will automatically scale the width to preserve dimensions.
shape->set_Height(125);
ASPOSE_ASSERT_EQ(125.0, shape->get_Width());
// The "Bottom" and "Right" properties contain the bottom and right edges of the image.
ASPOSE_ASSERT_EQ(shape->get_Top() + shape->get_Height(), shape->get_Bottom());
ASPOSE_ASSERT_EQ(shape->get_Left() + shape->get_Width(), shape->get_Right());
doc->Save(ArtifactsDir + u"Image.CreateFloatingPositionSize.docx");

◆ get_PaperSize()

Aspose::Words::PaperSize Aspose::Words::PageSetup::get_PaperSize ( )

Returns or sets the paper size.

Setting this property updates PageWidth and PageHeight values. Setting this value to Custom does not change existing values.

Examples

Shows how to adjust paper size, orientation, margins, along with other settings for a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_PageSetup()->set_PaperSize(PaperSize::Legal);
builder->get_PageSetup()->set_Orientation(Orientation::Landscape);
builder->get_PageSetup()->set_TopMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_BottomMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_LeftMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_RightMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_HeaderDistance(ConvertUtil::InchToPoint(0.2));
builder->get_PageSetup()->set_FooterDistance(ConvertUtil::InchToPoint(0.2));
builder->Writeln(u"Hello world!");
doc->Save(ArtifactsDir + u"PageSetup.PageMargins.docx");

Shows how to set page sizes.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// We can change the current page's size to a pre-defined size
// by using the "PaperSize" property of this section's PageSetup object.
builder->get_PageSetup()->set_PaperSize(PaperSize::Tabloid);
ASPOSE_ASSERT_EQ(792.0, builder->get_PageSetup()->get_PageWidth());
ASPOSE_ASSERT_EQ(1224.0, builder->get_PageSetup()->get_PageHeight());
builder->Writeln(String::Format(u"This page is {0}x{1}.", builder->get_PageSetup()->get_PageWidth(), builder->get_PageSetup()->get_PageHeight()));
// Each section has its own PageSetup object. When we use a document builder to make a new section,
// that section's PageSetup object inherits all the previous section's PageSetup object's values.
builder->InsertBreak(BreakType::SectionBreakEvenPage);
ASSERT_EQ(PaperSize::Tabloid, builder->get_PageSetup()->get_PaperSize());
builder->get_PageSetup()->set_PaperSize(PaperSize::A5);
builder->Writeln(String::Format(u"This page is {0}x{1}.", builder->get_PageSetup()->get_PageWidth(), builder->get_PageSetup()->get_PageHeight()));
ASPOSE_ASSERT_EQ(419.55, builder->get_PageSetup()->get_PageWidth());
ASPOSE_ASSERT_EQ(595.30, builder->get_PageSetup()->get_PageHeight());
builder->InsertBreak(BreakType::SectionBreakEvenPage);
// Set a custom size for this section's pages.
builder->get_PageSetup()->set_PageWidth(620);
builder->get_PageSetup()->set_PageHeight(480);
ASSERT_EQ(PaperSize::Custom, builder->get_PageSetup()->get_PaperSize());
builder->Writeln(String::Format(u"This page is {0}x{1}.", builder->get_PageSetup()->get_PageWidth(), builder->get_PageSetup()->get_PageHeight()));
doc->Save(ArtifactsDir + u"PageSetup.PaperSizes.docx");

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_RestartPageNumbering()

bool Aspose::Words::PageSetup::get_RestartPageNumbering ( )

True if page numbering restarts at the beginning of the section.

Examples

Shows how to set up page numbering in a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Section 1, page 1.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Section 1, page 2.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Section 1, page 3.");
builder->InsertBreak(BreakType::SectionBreakNewPage);
builder->Writeln(u"Section 2, page 1.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Section 2, page 2.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Section 2, page 3.");
// Move the document builder to the first section's primary header,
// which every page in that section will display.
builder->MoveToSection(0);
builder->MoveToHeaderFooter(HeaderFooterType::HeaderPrimary);
// Insert a PAGE field, which will display the number of the current page.
builder->Write(u"Page ");
builder->InsertField(u"PAGE", u"");
// Configure the section to have the page count that PAGE fields display start from 5.
// Also, configure all PAGE fields to display their page numbers using uppercase Roman numerals.
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->set_RestartPageNumbering(true);
pageSetup->set_PageStartingNumber(5);
pageSetup->set_PageNumberStyle(NumberStyle::UppercaseRoman);
// Create another primary header for the second section, with another PAGE field.
builder->MoveToSection(1);
builder->MoveToHeaderFooter(HeaderFooterType::HeaderPrimary);
builder->get_ParagraphFormat()->set_Alignment(ParagraphAlignment::Center);
builder->Write(u" - ");
builder->InsertField(u"PAGE", u"");
builder->Write(u" - ");
// Configure the section to have the page count that PAGE fields display start from 10.
// Also, configure all PAGE fields to display their page numbers using Arabic numbers.
pageSetup = doc->get_Sections()->idx_get(1)->get_PageSetup();
pageSetup->set_PageStartingNumber(10);
pageSetup->set_RestartPageNumbering(true);
pageSetup->set_PageNumberStyle(NumberStyle::Arabic);
doc->Save(ArtifactsDir + u"PageSetup.PageNumbering.docx");

◆ get_RightMargin()

double Aspose::Words::PageSetup::get_RightMargin ( )

Returns or sets the distance (in points) between the right edge of the page and the right boundary of the body text.

Examples

Shows how to adjust paper size, orientation, margins, along with other settings for a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_PageSetup()->set_PaperSize(PaperSize::Legal);
builder->get_PageSetup()->set_Orientation(Orientation::Landscape);
builder->get_PageSetup()->set_TopMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_BottomMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_LeftMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_RightMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_HeaderDistance(ConvertUtil::InchToPoint(0.2));
builder->get_PageSetup()->set_FooterDistance(ConvertUtil::InchToPoint(0.2));
builder->Writeln(u"Hello world!");
doc->Save(ArtifactsDir + u"PageSetup.PageMargins.docx");

◆ get_RtlGutter()

bool Aspose::Words::PageSetup::get_RtlGutter ( )

Gets or sets whether Microsoft Word uses gutters for the section based on a right-to-left language or a left-to-right language.

Examples

Shows how to set gutter margins.

auto doc = MakeObject<Document>();
// Insert text that spans several pages.
auto builder = MakeObject<DocumentBuilder>(doc);
for (int i = 0; i < 6; i++)
{
builder->Write(String(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, ") +
u"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
builder->InsertBreak(BreakType::PageBreak);
}
// A gutter adds whitespaces to either the left or right page margin,
// which makes up for the center folding of pages in a book encroaching on the page's layout.
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
// Determine how much space our pages have for text within the margins and then add an amount to pad a margin.
ASSERT_NEAR(470.30, pageSetup->get_PageWidth() - pageSetup->get_LeftMargin() - pageSetup->get_RightMargin(), 0.01);
pageSetup->set_Gutter(100.0);
// Set the "RtlGutter" property to "true" to place the gutter in a more suitable position for right-to-left text.
pageSetup->set_RtlGutter(true);
// Set the "MultiplePages" property to "MultiplePagesType.MirrorMargins" to alternate
// the left/right page side position of margins every page.
pageSetup->set_MultiplePages(MultiplePagesType::MirrorMargins);
doc->Save(ArtifactsDir + u"PageSetup.Gutter.docx");

◆ get_SectionStart()

Aspose::Words::SectionStart Aspose::Words::PageSetup::get_SectionStart ( )

Returns or sets the type of section break for the specified object.

Examples

Shows how to specify how a new section separates itself from the previous.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"This text is in section 1.");
// Section break types determine how a new section separates itself from the previous section.
// Below are five types of section breaks.
// 1 - Starts the next section on a new page:
builder->InsertBreak(BreakType::SectionBreakNewPage);
builder->Writeln(u"This text is in section 2.");
ASSERT_EQ(SectionStart::NewPage, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_SectionStart());
// 2 - Starts the next section on the current page:
builder->InsertBreak(BreakType::SectionBreakContinuous);
builder->Writeln(u"This text is in section 3.");
ASSERT_EQ(SectionStart::Continuous, doc->get_Sections()->idx_get(2)->get_PageSetup()->get_SectionStart());
// 3 - Starts the next section on a new even page:
builder->InsertBreak(BreakType::SectionBreakEvenPage);
builder->Writeln(u"This text is in section 4.");
ASSERT_EQ(SectionStart::EvenPage, doc->get_Sections()->idx_get(3)->get_PageSetup()->get_SectionStart());
// 4 - Starts the next section on a new odd page:
builder->InsertBreak(BreakType::SectionBreakOddPage);
builder->Writeln(u"This text is in section 5.");
ASSERT_EQ(SectionStart::OddPage, doc->get_Sections()->idx_get(4)->get_PageSetup()->get_SectionStart());
// 5 - Starts the next section on a new column:
SharedPtr<TextColumnCollection> columns = builder->get_PageSetup()->get_TextColumns();
columns->SetCount(2);
builder->InsertBreak(BreakType::SectionBreakNewColumn);
builder->Writeln(u"This text is in section 6.");
ASSERT_EQ(SectionStart::NewColumn, doc->get_Sections()->idx_get(5)->get_PageSetup()->get_SectionStart());
doc->Save(ArtifactsDir + u"PageSetup.SetSectionStart.docx");

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_SheetsPerBooklet()

int32_t Aspose::Words::PageSetup::get_SheetsPerBooklet ( )

Returns or sets the number of pages to be included in each booklet.

Examples

Shows how to configure a document that can be printed as a book fold.

auto doc = MakeObject<Document>();
// Insert text that spans 16 pages.
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"My Booklet:");
for (int i = 0; i < 15; i++)
{
builder->InsertBreak(BreakType::PageBreak);
builder->Write(String::Format(u"Booklet face #{0}", i));
}
// Configure the first section's "PageSetup" property to print the document in the form of a book fold.
// When we print this document on both sides, we can take the pages to stack them
// and fold them all down the middle at once. The contents of the document will line up into a book fold.
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->set_MultiplePages(MultiplePagesType::BookFoldPrinting);
// We can only specify the number of sheets in multiples of 4.
pageSetup->set_SheetsPerBooklet(4);
doc->Save(ArtifactsDir + u"PageSetup.Booklet.docx");

◆ get_SuppressEndnotes()

bool Aspose::Words::PageSetup::get_SuppressEndnotes ( )

True if endnotes are printed at the end of the next section that doesn't suppress endnotes. Suppressed endnotes are printed before the endnotes in that section.

Examples

Shows how to store endnotes at the end of each section, and modify their positions.

void SuppressEndnotes()
{
auto doc = MakeObject<Document>();
doc->RemoveAllChildren();
// By default, a document compiles all endnotes at its end.
ASSERT_EQ(EndnotePosition::EndOfDocument, doc->get_EndnoteOptions()->get_Position());
// We use the "Position" property of the document's "EndnoteOptions" object
// to collect endnotes at the end of each section instead.
doc->get_EndnoteOptions()->set_Position(EndnotePosition::EndOfSection);
InsertSectionWithEndnote(doc, u"Section 1", u"Endnote 1, will stay in section 1");
InsertSectionWithEndnote(doc, u"Section 2", u"Endnote 2, will be pushed down to section 3");
InsertSectionWithEndnote(doc, u"Section 3", u"Endnote 3, will stay in section 3");
// While getting sections to display their respective endnotes, we can set the "SuppressEndnotes" flag
// of a section's "PageSetup" object to "true" to revert to the default behavior and pass its endnotes
// onto the next section.
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(1)->get_PageSetup();
pageSetup->set_SuppressEndnotes(true);
doc->Save(ArtifactsDir + u"PageSetup.SuppressEndnotes.docx");
}
static void InsertSectionWithEndnote(SharedPtr<Document> doc, String sectionBodyText, String endnoteText)
{
auto section = MakeObject<Section>(doc);
doc->AppendChild(section);
auto body = MakeObject<Body>(doc);
section->AppendChild(body);
ASPOSE_ASSERT_EQ(section, body->get_ParentNode());
auto para = MakeObject<Paragraph>(doc);
body->AppendChild(para);
ASPOSE_ASSERT_EQ(body, para->get_ParentNode());
auto builder = MakeObject<DocumentBuilder>(doc);
builder->MoveTo(para);
builder->Write(sectionBodyText);
builder->InsertFootnote(FootnoteType::Endnote, endnoteText);
}

◆ get_TextColumns()

System::SharedPtr<Aspose::Words::TextColumnCollection> Aspose::Words::PageSetup::get_TextColumns ( )

Returns a collection that represents the set of text columns.

Examples

Shows how to create multiple evenly spaced columns in a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<TextColumnCollection> columns = builder->get_PageSetup()->get_TextColumns();
columns->set_Spacing(100);
columns->SetCount(2);
builder->Writeln(u"Column 1.");
builder->InsertBreak(BreakType::ColumnBreak);
builder->Writeln(u"Column 2.");
doc->Save(ArtifactsDir + u"PageSetup.ColumnsSameWidth.docx");

◆ get_TextOrientation()

Aspose::Words::TextOrientation Aspose::Words::PageSetup::get_TextOrientation ( )

Allows to specify TextOrientation for the whole page. Default value is Horizontal

Examples

Shows how to set text orientation.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello world!");
// Set the "TextOrientation" property to "TextOrientation.Upward" to rotate all the text 90 degrees
// to the right so that all left-to-right text now goes top-to-bottom.
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->set_TextOrientation(TextOrientation::Upward);
doc->Save(ArtifactsDir + u"PageSetup.SetTextOrientation.docx");

◆ get_TopMargin()

double Aspose::Words::PageSetup::get_TopMargin ( )

Returns or sets the distance (in points) between the top edge of the page and the top boundary of the body text.

Examples

Shows how to adjust paper size, orientation, margins, along with other settings for a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_PageSetup()->set_PaperSize(PaperSize::Legal);
builder->get_PageSetup()->set_Orientation(Orientation::Landscape);
builder->get_PageSetup()->set_TopMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_BottomMargin(ConvertUtil::InchToPoint(1.0));
builder->get_PageSetup()->set_LeftMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_RightMargin(ConvertUtil::InchToPoint(1.5));
builder->get_PageSetup()->set_HeaderDistance(ConvertUtil::InchToPoint(0.2));
builder->get_PageSetup()->set_FooterDistance(ConvertUtil::InchToPoint(0.2));
builder->Writeln(u"Hello world!");
doc->Save(ArtifactsDir + u"PageSetup.PageMargins.docx");

◆ get_VerticalAlignment()

Aspose::Words::PageVerticalAlignment Aspose::Words::PageSetup::get_VerticalAlignment ( )

Returns or sets the vertical alignment of text on each page in a document or section.

Examples

Shows how to apply and revert page setup settings to sections in a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Modify the page setup properties for the builder's current section and add text.
builder->get_PageSetup()->set_Orientation(Orientation::Landscape);
builder->get_PageSetup()->set_VerticalAlignment(PageVerticalAlignment::Center);
builder->Writeln(u"This is the first section, which landscape oriented with vertically centered text.");
// If we start a new section using a document builder,
// it will inherit the builder's current page setup properties.
builder->InsertBreak(BreakType::SectionBreakNewPage);
ASSERT_EQ(Orientation::Landscape, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_Orientation());
ASSERT_EQ(PageVerticalAlignment::Center, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_VerticalAlignment());
// We can revert its page setup properties to their default values using the "ClearFormatting" method.
builder->get_PageSetup()->ClearFormatting();
ASSERT_EQ(Orientation::Portrait, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_Orientation());
ASSERT_EQ(PageVerticalAlignment::Top, doc->get_Sections()->idx_get(1)->get_PageSetup()->get_VerticalAlignment());
builder->Writeln(u"This is the second section, which is in default Letter paper size, portrait orientation and top alignment.");
doc->Save(ArtifactsDir + u"PageSetup.ClearFormatting.docx");

◆ GetType()

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

◆ Is()

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

◆ set_Bidi()

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

◆ set_BorderAlwaysInFront()

void Aspose::Words::PageSetup::set_BorderAlwaysInFront ( bool  value)

◆ set_BorderAppliesTo()

void Aspose::Words::PageSetup::set_BorderAppliesTo ( Aspose::Words::PageBorderAppliesTo  value)

◆ set_BorderDistanceFrom()

void Aspose::Words::PageSetup::set_BorderDistanceFrom ( Aspose::Words::PageBorderDistanceFrom  value)

◆ set_BorderSurroundsFooter()

void Aspose::Words::PageSetup::set_BorderSurroundsFooter ( bool  value)

◆ set_BorderSurroundsHeader()

void Aspose::Words::PageSetup::set_BorderSurroundsHeader ( bool  value)

◆ set_BottomMargin()

void Aspose::Words::PageSetup::set_BottomMargin ( double  value)

◆ set_CharactersPerLine()

void Aspose::Words::PageSetup::set_CharactersPerLine ( int32_t  value)

◆ set_DifferentFirstPageHeaderFooter()

void Aspose::Words::PageSetup::set_DifferentFirstPageHeaderFooter ( bool  value)

◆ set_FirstPageTray()

void Aspose::Words::PageSetup::set_FirstPageTray ( int32_t  value)

Sets the paper tray (bin) to use for the first page of a section. The value is implementation (printer) specific.

◆ set_FooterDistance()

void Aspose::Words::PageSetup::set_FooterDistance ( double  value)

◆ set_Gutter()

void Aspose::Words::PageSetup::set_Gutter ( double  value)

◆ set_HeaderDistance()

void Aspose::Words::PageSetup::set_HeaderDistance ( double  value)

◆ set_LayoutMode()

void Aspose::Words::PageSetup::set_LayoutMode ( Aspose::Words::SectionLayoutMode  value)

◆ set_LeftMargin()

void Aspose::Words::PageSetup::set_LeftMargin ( double  value)

◆ set_LineNumberCountBy()

void Aspose::Words::PageSetup::set_LineNumberCountBy ( int32_t  value)

◆ set_LineNumberDistanceFromText()

void Aspose::Words::PageSetup::set_LineNumberDistanceFromText ( double  value)

◆ set_LineNumberRestartMode()

void Aspose::Words::PageSetup::set_LineNumberRestartMode ( Aspose::Words::LineNumberRestartMode  value)

◆ set_LinesPerPage()

void Aspose::Words::PageSetup::set_LinesPerPage ( int32_t  value)

◆ set_LineStartingNumber()

void Aspose::Words::PageSetup::set_LineStartingNumber ( int32_t  value)

◆ set_MultiplePages()

void Aspose::Words::PageSetup::set_MultiplePages ( Aspose::Words::Settings::MultiplePagesType  value)

◆ set_OddAndEvenPagesHeaderFooter()

void Aspose::Words::PageSetup::set_OddAndEvenPagesHeaderFooter ( bool  value)

◆ set_Orientation()

void Aspose::Words::PageSetup::set_Orientation ( Aspose::Words::Orientation  value)

◆ set_OtherPagesTray()

void Aspose::Words::PageSetup::set_OtherPagesTray ( int32_t  value)

Sets the paper tray (bin) to be used for all but the first page of a section. The value is implementation (printer) specific.

◆ set_PageHeight()

void Aspose::Words::PageSetup::set_PageHeight ( double  value)

◆ set_PageNumberStyle()

void Aspose::Words::PageSetup::set_PageNumberStyle ( Aspose::Words::NumberStyle  value)

◆ set_PageStartingNumber()

void Aspose::Words::PageSetup::set_PageStartingNumber ( int32_t  value)

◆ set_PageWidth()

void Aspose::Words::PageSetup::set_PageWidth ( double  value)

◆ set_PaperSize()

void Aspose::Words::PageSetup::set_PaperSize ( Aspose::Words::PaperSize  value)

◆ set_RestartPageNumbering()

void Aspose::Words::PageSetup::set_RestartPageNumbering ( bool  value)

◆ set_RightMargin()

void Aspose::Words::PageSetup::set_RightMargin ( double  value)

◆ set_RtlGutter()

void Aspose::Words::PageSetup::set_RtlGutter ( bool  value)

◆ set_SectionStart()

void Aspose::Words::PageSetup::set_SectionStart ( Aspose::Words::SectionStart  value)

◆ set_SheetsPerBooklet()

void Aspose::Words::PageSetup::set_SheetsPerBooklet ( int32_t  value)

◆ set_SuppressEndnotes()

void Aspose::Words::PageSetup::set_SuppressEndnotes ( bool  value)

◆ set_TextOrientation()

void Aspose::Words::PageSetup::set_TextOrientation ( Aspose::Words::TextOrientation  value)

◆ set_TopMargin()

void Aspose::Words::PageSetup::set_TopMargin ( double  value)

◆ set_VerticalAlignment()

void Aspose::Words::PageSetup::set_VerticalAlignment ( Aspose::Words::PageVerticalAlignment  value)

◆ Type()

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