Page Setup

Page setup is a set of page layout and formatting options that affect how the content appears on the page. With page setup you can specify options like page orientation, size, and margins.

Each Section has a PageSetup property which defines display and layout settings of all pages that its content occupies.

The following example shows how you can set some page setup properties like orientation, margins, and paper type.

Word document with set page options like size and margin
Screenshot of Word file with specified page options
using GemBox.Document;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var document = new DocumentModel();

        document.Sections.Add(
            new Section(document,
                new Paragraph(document, "First section's page.")));

        document.Sections.Add(
            new Section(document,
                new Paragraph(document, "Second section's page, first paragraph."),
                new Paragraph(document, "Second section's page, second paragraph."),
                new Paragraph(document, "Second section's page, third paragraph.")));

        var pageSetup1 = document.Sections[0].PageSetup;
        var pageSetup2 = document.Sections[1].PageSetup;

        // Set page orientation.
        pageSetup1.Orientation = Orientation.Landscape;

        // Set page margins.
        pageSetup1.PageMargins.Top = 10;
        pageSetup1.PageMargins.Bottom = 10;

        // Set paper type.
        pageSetup2.PaperType = PaperType.A5;

        // Set line numbering.
        pageSetup2.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 New DocumentModel()

        document.Sections.Add(
            New Section(document,
                New Paragraph(document, "First section's page.")))

        document.Sections.Add(
            New Section(document,
                New Paragraph(document, "Second section's page, first paragraph."),
                New Paragraph(document, "Second section's page, second paragraph."),
                New Paragraph(document, "Second section's page, third paragraph.")))

        Dim pageSetup1 = document.Sections(0).PageSetup
        Dim pageSetup2 = document.Sections(1).PageSetup

        ' Set page orientation.
        pageSetup1.Orientation = Orientation.Landscape

        ' Set page margins.
        pageSetup1.PageMargins.Top = 10
        pageSetup1.PageMargins.Bottom = 10

        ' Set paper type.
        pageSetup2.PaperType = PaperType.A5

        ' Set line numbering.
        pageSetup2.LineNumberRestartSetting = LineNumberRestartSetting.NewPage

        document.Save("Page Setup.%OutputFileType%")

    End Sub
End Module

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Document yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.