Page Setup

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

Following sample 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.


1using System;
2using System.IO;
3using System.Linq;
4using GemBox.Document;
5using GemBox.Document.Drawing;
6
7class Sample
8{
9    [STAThread]
10    static void Main(string[] args)
11    {
12        // If using Professional version, put your serial key below.
13        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
14
15        DocumentModel document = new DocumentModel();
16
17        Section section = new Section(document,
18            new Paragraph(document,
19                new Run(document, "First line"),
20                new SpecialCharacter(document, SpecialCharacterType.LineBreak),
21                new Run(document, "Second line"),
22                new SpecialCharacter(document, SpecialCharacterType.LineBreak),
23                new Run(document, "Third line")),
24            new Paragraph(document,
25                new SpecialCharacter(document, SpecialCharacterType.ColumnBreak),
26                new Run(document, "First line"),
27                new SpecialCharacter(document, SpecialCharacterType.LineBreak),
28                new Run(document, "Second line"),
29                new SpecialCharacter(document, SpecialCharacterType.LineBreak),
30                new Run(document, "Third line")));
31
32        PageSetup pageSetup = section.PageSetup;
33
34        // Specify text columns.
35        pageSetup.TextColumns = new TextColumnCollection(2)
36        {
37            LineBetween = true,
38            EvenlySpaced = false
39        };
40        pageSetup.TextColumns[0].Width = LengthUnitConverter.Convert(1, LengthUnit.Inch, LengthUnit.Point);
41        pageSetup.TextColumns[1].Width = LengthUnitConverter.Convert(2.3, LengthUnit.Inch, LengthUnit.Point);
42
43        // Specify paper type.
44        pageSetup.PaperType = PaperType.A5;
45
46        document.Sections.Add(section);
47
48        // Specify line numbering.
49        document.Sections.Add(
50            new Section(document,
51                new Paragraph(document,
52                new Run(document, "First line"),
53                new SpecialCharacter(document, SpecialCharacterType.LineBreak),
54                new Run(document, "Second line"),
55                new SpecialCharacter(document, SpecialCharacterType.LineBreak),
56                new Run(document, "Third line")))
57            {
58                PageSetup = new PageSetup()
59                {
60                    PaperType = PaperType.A5,
61                    LineNumberRestartSetting = LineNumberRestartSetting.NewPage
62                }
63            });
64
65        document.Save("Page Setup.docx");
66    }
67}
1Imports System
2Imports System.IO
3Imports System.Linq
4Imports GemBox.Document
5Imports GemBox.Document.Drawing
6
7Module Samples
8
9    Sub Main()
10
11        ' If using Professional version, put your serial key below.
12        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
13
14        Dim document As DocumentModel = New DocumentModel
15
16        Dim section As New Section(document,
17                New Paragraph(document,
18                    New Run(document, "First line"),
19                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
20                    New Run(document, "Second line"),
21                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
22                    New Run(document, "Third line")),
23                New Paragraph(document,
24                    New SpecialCharacter(document, SpecialCharacterType.ColumnBreak),
25                    New Run(document, "First line"),
26                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
27                    New Run(document, "Second line"),
28                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
29                    New Run(document, "Third line")))
30
31        Dim pageSetup As PageSetup = section.PageSetup
32
33        ' Specify text columns.
34        pageSetup.TextColumns = New TextColumnCollection(2) With {
35            .LineBetween = True,
36            .EvenlySpaced = False
37        }
38
39        pageSetup.TextColumns(0).Width = LengthUnitConverter.Convert(1, LengthUnit.Inch, LengthUnit.Point)
40        pageSetup.TextColumns(1).Width = LengthUnitConverter.Convert(2.3, LengthUnit.Inch, LengthUnit.Point)
41
42        ' Specify paper type.
43        pageSetup.PaperType = PaperType.A5
44
45        document.Sections.Add(section)
46
47        ' Specify line numbering.
48        document.Sections.Add(
49            New Section(document,
50                New Paragraph(document,
51                    New Run(document, "First line"),
52                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
53                    New Run(document, "Second line"),
54                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
55                    New Run(document, "Third line"))) With {
56                        .PageSetup = New PageSetup() With {
57                            .PaperType = PaperType.A5,
58                            .LineNumberRestartSetting = LineNumberRestartSetting.NewPage
59         }})
60
61        document.Save("Page Setup.docx")
62
63    End Sub
64
65End Module

Check next sample or find out more about GemBox.Document and GemBox Software.