Click or drag to resize

PageSetup Class

Represents the page setup properties: paper type, orientation, margins and so forth.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentPageSetup

Namespace: SautinSoft.Document
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.4.24
Syntax
public sealed class PageSetup

The PageSetup type exposes the following members.

Constructors
 NameDescription
Public methodCode examplePageSetup Initializes a new instance of the PageSetup class.
Top
Properties
 NameDescription
Public propertyBorders Gets collection of borders of the page.
Public propertyLineNumberDistanceFromText Gets or sets the line number distance from text (in points).
Public propertyLineNumberIncrement Gets or sets the line number increments to be displayed.
Public propertyLineNumberRestartSetting Gets or sets the line number restart setting
Public propertyLineStartingNumber Gets or sets the line starting number.
Public propertyCode exampleOrientation Gets or sets the page orientation.
Public propertyPageColor Gets or sets the background color for all pages of the parent section.
Public propertyCode examplePageHeight Gets or sets the height of the page (in points).
Public propertyCode examplePageMargins Gets or sets the page margins.
Public propertyPageNumberStyle Gets or sets the number style for the page number.
Public propertyPageStartingNumber Gets or sets the number that appears on the first page of the section.
Public propertyCode examplePageWidth Gets or sets the width of the page (in points).
Public propertyCode examplePaperType Gets or sets the type of the paper for the page.
Public propertySectionStart Gets or sets the type of section start.
Public propertyCode exampleTextColumns Gets or sets the text columns.
Public propertyCode exampleTitlePage Gets or sets a value indicating whether the parent section of the document shall have a different header and footer for its first page.
Top
Methods
 NameDescription
Public methodClearFormatting Clears the formatting.
Public methodClone Clones this PageSetup instance.
Top
Example

See Developer Guide: How to adjust a document page properties

How to adjust a document page properties in C#
using SautinSoft.Document;

namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            // Get your free 30-day key here:   
            // https://sautinsoft.com/start-for-free/

            PageProperties();
        }

        /// <summary>
        /// How to adjust a document page properties. 
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/page-setup.php
        /// </remarks>
        public static void PageProperties()
        {
            string documentPath = @"PageProperties.docx";

            // Let's create a simple document.
            DocumentCore dc = new DocumentCore();

            // Add new section, B5 Landscape, and custom page margins.
            Section section1 = new Section(dc);
            section1.PageSetup.PaperType = PaperType.B5;
            section1.PageSetup.Orientation = Orientation.Landscape;
            section1.PageSetup.PageMargins = new PageMargins()
            {
                Top = LengthUnitConverter.Convert(50, LengthUnit.Millimeter, LengthUnit.Point),
                Right = LengthUnitConverter.Convert(1, LengthUnit.Inch, LengthUnit.Point),
                Bottom = LengthUnitConverter.Convert(10, LengthUnit.Millimeter, LengthUnit.Point),
                Left = LengthUnitConverter.Convert(2, LengthUnit.Centimeter, LengthUnit.Point)
            };

            dc.Sections.Add(section1);

            // Add some text to section1.
            section1.Content.Start.Insert("Shrek, a green ogre who loves the solitude in his swamp, " +
                            "finds his life interrupted when many fairytale characters are " +
                            "exiled there by order of the fairytale-hating Lord Farquaad.", new CharacterFormat() { FontName = "Times New Roman", Size = 14.0 });

            // Add page break.
            section1.Content.End.Insert(new SpecialCharacter(dc, SpecialCharacterType.PageBreak).Content);

            // Add another section, A4 Portrait, and custom page margins.
            Section section2 = new Section(dc);
            section2.PageSetup.PaperType = PaperType.A4;
            section2.PageSetup.Orientation = Orientation.Portrait;
            section2.PageSetup.PageMargins = new PageMargins()
            {
                Top = LengthUnitConverter.Convert(5, LengthUnit.Millimeter, LengthUnit.Point),
                Right = LengthUnitConverter.Convert(5, LengthUnit.Millimeter, LengthUnit.Point),
                Bottom = LengthUnitConverter.Convert(5, LengthUnit.Millimeter, LengthUnit.Point),
                Left = LengthUnitConverter.Convert(5, LengthUnit.Millimeter, LengthUnit.Point)
            };

            dc.Sections.Add(section2);

            // Add some text into section2.
            Paragraph p = new Paragraph(dc);
            p.Content.Start.Insert("Shrek tells them that he will go ask Farquaad to send them back. " +
                                    "He brings along a talking Donkey who is the only fairytale creature who knows the way to Duloc.",
                                    new CharacterFormat() { FontName = "Times New Roman", Size = 14.0 });
            p.ParagraphFormat.Alignment = HorizontalAlignment.Justify;
            section2.Blocks.Add(p);

            // Save our document into DOCX format.
            dc.Save(documentPath);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath) { UseShellExecute = true });
        }
    }
}
How to adjust a document page properties in VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
        PageProperties()
    End Sub
    ''' Get your free 30-day key here:   
    ''' https://sautinsoft.com/start-for-free/
    ''' <summary>
    ''' How to adjust a document page properties. 
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/page-setup.php
    ''' </remarks>
    Sub PageProperties()
        Dim documentPath As String = "PageProperties.docx"

        ' Let's create a simple document.
        Dim dc As New DocumentCore()

        ' Add new section, B5 Landscape, and custom page margins.
        Dim section1 As New Section(dc)
        section1.PageSetup.PaperType = PaperType.B5
        section1.PageSetup.Orientation = Orientation.Landscape
        section1.PageSetup.PageMargins = New PageMargins() With {
                .Top = LengthUnitConverter.Convert(50, LengthUnit.Millimeter, LengthUnit.Point),
                .Right = LengthUnitConverter.Convert(1, LengthUnit.Inch, LengthUnit.Point),
                .Bottom = LengthUnitConverter.Convert(10, LengthUnit.Millimeter, LengthUnit.Point),
                .Left = LengthUnitConverter.Convert(2, LengthUnit.Centimeter, LengthUnit.Point)
            }

        dc.Sections.Add(section1)

        ' Add some text to section1.
        section1.Content.Start.Insert("Shrek, a green ogre who loves the solitude in his swamp, " & "finds his life interrupted when many fairytale characters are " & "exiled there by order of the fairytale-hating Lord Farquaad.", New CharacterFormat() With {
                .FontName = "Times New Roman",
                .Size = 14.0
            })

        ' Add page break.
        section1.Content.End.Insert((New SpecialCharacter(dc, SpecialCharacterType.PageBreak)).Content)

        ' Add another section, A4 Portrait, and custom page margins.
        Dim section2 As New Section(dc)
        section2.PageSetup.PaperType = PaperType.A4
        section2.PageSetup.Orientation = Orientation.Portrait
        section2.PageSetup.PageMargins = New PageMargins() With {
                .Top = LengthUnitConverter.Convert(5, LengthUnit.Millimeter, LengthUnit.Point),
                .Right = LengthUnitConverter.Convert(5, LengthUnit.Millimeter, LengthUnit.Point),
                .Bottom = LengthUnitConverter.Convert(5, LengthUnit.Millimeter, LengthUnit.Point),
                .Left = LengthUnitConverter.Convert(5, LengthUnit.Millimeter, LengthUnit.Point)
            }

        dc.Sections.Add(section2)

        ' Add some text into section2.
        Dim p As New Paragraph(dc)
        p.Content.Start.Insert("Shrek tells them that he will go ask Farquaad to send them back. " & "He brings along a talking Donkey who is the only fairytale creature who knows the way to Duloc.", New CharacterFormat() With {
                .FontName = "Times New Roman",
                .Size = 14.0
            })
        p.ParagraphFormat.Alignment = HorizontalAlignment.Justify
        section2.Blocks.Add(p)

        ' Save our document into DOCX format.
        dc.Save(documentPath)

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(documentPath) With {.UseShellExecute = True})
    End Sub
End Module
See Also