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.

Page Setup Screenshot
using GemBox.Document;

class Program
{
    static void Main()
    {
        // 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.%OutputFileType%");
    }
}
Imports GemBox.Document

Module Program

    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.%OutputFileType%")

    End Sub

End Module

Check next example or download examples from GitHub.