Click or drag to resize
Pdf Library for .NET

Page Settings

Select.Pdf can be used to control how a page looks like when it is added to a pdf document. The most important properties of a pdf page are:

  • Page size

  • Page orientation

  • Page margins

Page size

SelectPdf supports the following standard page sizes:

  • A0 to A10

  • B0 to B5

  • ArchA to ArchE

  • Letter, HalfLetter, Letter11x17, Note, Flsa, Ledger

Pages with custom page sizes can also be created using Select.Pdf.

Page orientation

SelectPdf supports the following page orientations:

  • Portrait

  • Landscape

Page margins

Page margins can be set using PdfMargins object.

Adding a page to a pdf document

The page settings described above can be set when a new page is added to the pdf document.

// add a new page to the document 
// (with specific page size, margins and orientation)
PdfPage page = doc.AddPage(PdfCustomPageSize.A4, new PdfMargins(0f),
    PdfPageOrientation.Portrait);

The page size and orientation can also be modified directly on PdfPage object, but the page margins can be set only on the PdfDocument object, using either AddPage(PdfMargins) method or the Margins property.

A page added with no parameters specified uses the pdf document defaults, not the settings of the page before it: A4 size, Portrait orientation, and the margins of the Margins property (28 points on a new document). Each page keeps the size, orientation and margins it was added with, so a document can mix them freely - pass them to AddPage(PdfCustomPageSize, PdfMargins, PdfPageOrientation) whenever a page has to differ from those defaults.

Page Rotation

Rotation sets how a page is displayed: turned by 90, 180 or 270 degrees (PdfPageRotation). The rotation applies to the finished page, so content is placed the same way whether the page is rotated before or after it is drawn. It works on new pages, on the pages of a loaded document and on the pages of a converted document.

PdfPage page = doc.AddPage();
page.Rotation = PdfPageRotation.Rotate_90;
Sample Code

The sample code below create a first page with no margins, size A4 and Portrait orientation and a second page with 20pt for all margins, Letter size and Landscape orientation.

// create a new pdf document
PdfDocument doc = new PdfDocument();

// create a new pdf font
PdfFont font = doc.Fonts.Add(PdfStandardFont.Helvetica);
font.Size = 18;

// add a new page to the document 
// (with specific page size, margins and orientation)
PdfPage page = doc.AddPage(PdfCustomPageSize.A4, new PdfMargins(0f),
    PdfPageOrientation.Portrait);

// create a new text element and add it to the page
PdfTextElement text = new PdfTextElement(0, 0, Helper.SomeText(), font);
page.Add(text);

// add a new page to the document
// (with specific page size, margins and orientation)
PdfPage page2 = doc.AddPage(PdfCustomPageSize.Letter, new PdfMargins(20f),
    PdfPageOrientation.Landscape);

// create a new text element and add it to the page
PdfTextElement text2 = new PdfTextElement(0, 0, Helper.SomeText(), font);
page2.Add(text2);

// save pdf document
doc.Save(file);

// close pdf document
doc.Close();
See Also