SelectPdf for .NET - Pdf Page Settings - VB.NET / ASP.NET Sample

This sample shows how to create a new PDF document using SelectPdf and how to specify the page size, margins and orientation.

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

Sample code · VB.NET
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports SelectPdf

Namespace SelectPdf.Samples
    Partial Public Class page_settings
        Inherits System.Web.UI.Page

        Protected Sub BtnCreatePdf_Click(sender As Object, e As EventArgs)
            ' create a new pdf document
            Dim doc As New PdfDocument()

            ' create a new pdf font
            Dim font As PdfFont = doc.AddFont(PdfStandardFont.Helvetica)
            font.Size = 18

            ' add a new page to the document (with specific page size, margins and orientation)
            Dim page As PdfPage = doc.AddPage(PdfCustomPageSize.A4, _
                    New PdfMargins(0.0F), PdfPageOrientation.Portrait)

            ' create a new text element and add it to the page
            Dim text As New PdfTextElement(0, 0, Helper.SomeText(), font)
            page.Add(text)

            ' add a new page to the document (with specific page size, margins and orientation)
            Dim page2 As PdfPage = doc.AddPage(PdfCustomPageSize.Letter, _
                    New PdfMargins(20.0F), PdfPageOrientation.Landscape)

            ' create a new text element and add it to the page
            Dim text2 As New PdfTextElement(0, 0, Helper.SomeText(), font)
            page2.Add(text2)

            ' save pdf document
            doc.Save(Response, False, "Sample.pdf")

            ' close pdf document
            doc.Close()
        End Sub

    End Class
End Namespace