GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API.

Page Setup

Page setup is used to define page layout and printing properties on a group of pages - section.

Following example shows how to set page setup options like page size, text columns and paper type.

Screenshot
Page Setup Screenshot

See the full code below, use Run Example to execute.

using System;
using System.IO;
using System.Linq;
using GemBox.Document;
using GemBox.Document.Drawing;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = new DocumentModel();

        Section section = new Section(document,
            new Paragraph(document,
                new Run(document, "First line"),
                new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                new Run(document, "Second line"),
                new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                new Run(document, "Third line")),
            new Paragraph(document,
                new SpecialCharacter(document, SpecialCharacterType.ColumnBreak),
                new Run(document, "First line"),
                new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                new Run(document, "Second line"),
                new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                new Run(document, "Third line")));

        PageSetup pageSetup = section.PageSetup;

        // Specify text columns.
        pageSetup.TextColumns = new TextColumnCollection(2)
        {
            LineBetween = true,
            EvenlySpaced = false
        };
        pageSetup.TextColumns[0].Width = LengthUnitConverter.Convert(1, LengthUnit.Inch, LengthUnit.Point);
        pageSetup.TextColumns[1].Width = LengthUnitConverter.Convert(2.3, LengthUnit.Inch, LengthUnit.Point);

        // Specify paper type.
        pageSetup.PaperType = PaperType.A5;

        document.Sections.Add(section);

        // Specify line numbering.
        document.Sections.Add(
            new Section(document,
                new Paragraph(document,
                new Run(document, "First line"),
                new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                new Run(document, "Second line"),
                new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                new Run(document, "Third line")))
            {
                PageSetup = new PageSetup()
                {
                    PaperType = PaperType.A5,
                    LineNumberRestartSetting = LineNumberRestartSetting.NewPage
                }
            });

        document.Save("Page Setup.docx");
    }
}
Imports System
Imports System.IO
Imports System.Linq
Imports GemBox.Document
Imports GemBox.Document.Drawing

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document As DocumentModel = New DocumentModel

        Dim section As New Section(document,
                New Paragraph(document,
                    New Run(document, "First line"),
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Second line"),
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Third line")),
                New Paragraph(document,
                    New SpecialCharacter(document, SpecialCharacterType.ColumnBreak),
                    New Run(document, "First line"),
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Second line"),
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Third line")))

        Dim pageSetup As PageSetup = section.PageSetup

        ' Specify text columns.
        pageSetup.TextColumns = New TextColumnCollection(2) With {
            .LineBetween = True,
            .EvenlySpaced = False
        }

        pageSetup.TextColumns(0).Width = LengthUnitConverter.Convert(1, LengthUnit.Inch, LengthUnit.Point)
        pageSetup.TextColumns(1).Width = LengthUnitConverter.Convert(2.3, LengthUnit.Inch, LengthUnit.Point)

        ' Specify paper type.
        pageSetup.PaperType = PaperType.A5

        document.Sections.Add(section)

        ' Specify line numbering.
        document.Sections.Add(
            New Section(document,
                New Paragraph(document,
                    New Run(document, "First line"),
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Second line"),
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Third line"))) With {
                        .PageSetup = New PageSetup() With {
                            .PaperType = PaperType.A5,
                            .LineNumberRestartSetting = LineNumberRestartSetting.NewPage
         }})

        document.Save("Page Setup.docx")

    End Sub

End Module

Check next sample.