SelectPdf for .NET - Modify Existing Pdf - VB.NET / ASP.NET Sample

This sample shows how to use SelectPdf Library for .NET to load an existing document, add a new page to it and a new text element.

Here is our initial test pdf document:
Test file

Click on the "Create PDF" button below to see the result.

Sample Code Vb.Net

Public Class modify_existing_pdf
    Inherits System.Web.UI.Page

    Protected Sub BtnCreatePdf_Click(sender As Object, e As EventArgs)
        ' the initial file
        Dim file As String = Server.MapPath("~/files/doc1.pdf")

        ' load the pdf document
        Dim doc As New PdfDocument(file)

        ' add a new page to the document
        Dim page As PdfPage = doc.AddPage()

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

        ' create text element and add it to the new page
        Dim text As New PdfTextElement(100, 100, _
                "Sample text added to an existing pdf document.", font)

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

        ' close pdf document
    End Sub
End Class