SelectPdf for .NET - Pdf Merge - VB.NET / ASP.NET Sample

This sample shows how to use SelectPdf Library for .NET to merge 2 different pdf documents into a new pdf document.

Here are the 2 individual pdf documents:
File 1
File 2

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


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 pdf_merge
        Inherits System.Web.UI.Page

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

            ' load the 2 pdf documents
            Dim doc1 As New PdfDocument(file1)
            Dim doc2 As New PdfDocument(file2)

            ' create a new pdf document
            Dim doc As New PdfDocument()

            ' add the pages of those 2 documents to the new document
            doc.Append(doc1)
            doc.Append(doc2)

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

            ' close pdf document
            doc.Close()

            ' close the original pdf documents
            doc1.Close()
            doc2.Close()
        End Sub
    End Class
End Namespace