# Page Settings

Use DsWord to set the page properties such as page borders, size, margins, etc., insert or remove page break, and allow multipage printing in a Word document.

## Content

DsWord stores all the page setup attributes, such as page borders, size, margins, etc., as properties in the [PageSetup](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.PageSetup.html) class. These properties control the structure and layout of pages in a word document. DsWord also allows you to insert a page break which is especially required in case of a long document using [Type](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Break.Type.html) property of the [Break](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Break.html) class. The Type property takes **Page** as a value from [BreakType](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.BreakType.html) enumeration for specifying a page break. Moreover, DsWord lets you specify how a document is printed using [Type](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.MultiPagePrinting.Type.html) property of the [MultiPagePrinting](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.MultiPagePrinting.html) class. The Type property takes the value from [MultiPagePrintingType](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.MultiPagePrintingType.html) enumeration, so that the printed document can be bound as a booklet.

## Set Page Properties

To set the page properties:

1. Access the page setup properties using [PageSetup](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Section.PageSetup.html) property of the [Section](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Section.html) class.
2. Set the page size properties. For example, set the orientation of the page using the [Orientation](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.PageSize.Orientation.html) property and paper size using the [PaperSize](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.PageSize.PaperSize.html) property.
3. Set the page borders of the section using the [Borders](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.PageSetup.Borders.html) property and apply border to the pages using the [Border](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Border.html) class properties.

    ```csharp
    GcWordDocument doc = new GcWordDocument();
    doc.Load("SampleDoc.docx"); 
    Section first = doc.Body.Sections.First;
    
    first.PageSetup.Size.Orientation = PageOrientation.Landscape;
    first.PageSetup.Size.PaperSize = PaperSize.PaperLetter;
    
    first.PageSetup.Borders.AppliesTo = PageBorderAppliesTo.AllPages;
    first.PageSetup.Borders.Left.LineStyle = LineStyle.BabyPacifier;
    first.PageSetup.Borders.Right.LineStyle = LineStyle.BabyPacifier;
    first.PageSetup.Borders.AlwaysInFront = true;
    
    doc.Save("SetPageProperties.docx");
    ```

## Set Page Number

To set the page numbering:

1. Access the page setup properties using **PageSetup** property of the **Section** class.
2. Set the page numbering properties. For example, set the starting page number using the [StartingNumber](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.PageNumbering.StartingNumber.html) property and the page number format using [NumberStyle](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.PageNumbering.NumberStyle.html) property of the [PageNumbering](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.PageNumbering.html) class.
    This displays the page numbering when you click on the scroll handle, which is the default behavior. However, if you want to display the page number at the bottom of the page, you can insert a footer in the page and use a simple field in it.
3. Append a footer using the [Footers](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Section.Footers.html) property and add a paragraph to it using the Add method.
4. Add a simple field in the paragraph using [Add](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.SimpleFieldCollection.html) method of the [SimpleFieldCollection](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.SimpleFieldCollection.html) class.

    ```csharp
    doc.Load("SampleDoc.docx"); 
    Section first = doc.Body.Sections.First;
    
    //Set page numbering
    first.PageSetup.PageNumbering.StartingNumber = 3;
    first.PageSetup.PageNumbering.NumberStyle = NumberStyle.NumberInDash;
    first.Footers[HeaderFooterType.Primary].Body.Paragraphs.Add("");
    first.Footers[HeaderFooterType.Primary].Body.Paragraphs.First.GetRange().SimpleFields.Add("PAGE");
    
    //Save the document
    doc.Save("PageNumbering.docx");
    ```

## Insert Page Break

To insert page break in a Word document:

1. Access a paragraph in a section. For example, access first paragraph of the first section.
2. Add a page break on the desired location in the paragraph using [AddBreak](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.TextCollection.AddBreak.html) method of the [TextCollection](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.TextCollection.html) class. For example, add the page break after first run of the first paragraph.
3. Set the break type to Page using the [BreakType](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.BreakType.html) enum.

    ```csharp
    doc.Load("SampleDoc.docx");
    
    //Access the first paragraph of the first section
    Section first = doc.Body.Sections.First;
    Paragraph p1 = first.GetRange().Paragraphs.First;
    
    //Insert page break
    Break br1;
    br1 = p1.GetRange().Runs.First.GetRange().Texts.AddBreak(BreakType.Page);
    
    //Save the document
    doc.Save("SampleDoc_PageBreak.docx");
    ```

## Remove Page Break

To remove page break:

1. Get a list of all the breaks of type Page from the document.
2. Remove a page break using the [Delete](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.ContentObject.Delete.html) method. For example, remove the first page break.

    ```csharp
    //Load the document
    doc.Load("SampleDoc_PageBreak.docx");
    
    //Get a list of all the breaks of type "Page" that exist in the document
    var breaks = new List<Break>();
    foreach (var text in doc.Body.Texts)
    {
        Break x = text as Break;
        if (x != null && x.Type == BreakType.Page)
            breaks.Add(x);
    }
    
    //Remove the first page break
    breaks[0].Delete();
    
    //Save the document
    doc.Save("SampleDoc_NoPageBreak.docx");
    ```

## Multipage Printing

To print a multiple page document:

1. Access the options to print the multiple page document using [MultiPagePrinting](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.PageSetup.MultiPagePrinting.html) property of the **PageSetup** class.
2. Set the type for document printing using **Type** property of the **MultiPagePrinting** class.

    ```csharp
    doc.Load("SampleDoc.docx");
    //Two out of the three sheets in the document will be printed on one page 
    doc.Body.Sections.First.PageSetup.MultiPagePrinting.Type = 
        MultiPagePrintingType.TwoPagesPerSheet;
    
    doc.Save("MultiPagePrinting.docx");
    ```

For more information on how to work with pages and page breaks using DsWord, see [DsWord sample browser](https://developer.mescius.com/document-solutions/dot-net-word-api/demos/features/miscellaneous/remove-page-breaks/code-cs).