Imports SelectPdf

Namespace Controllers
    Public Class PdfSplitController
        Inherits Controller

        ' GET: PdfSplit
        Public Function Index() As ActionResult
            Return View()
        End Function

        <HttpPost> _
        Public Function SubmitAction(collection As FormCollection) As ActionResult
            ' the initial file
            Dim file1 As String = Server.MapPath("~/files/doc.pdf")

            ' load the pdf document
            Dim doc1 As New PdfDocument(file1)

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

            ' add 2 pages to the new document
            If doc1.Pages.Count > 2 Then
                doc.AddPage(doc1.Pages(1))
                doc.AddPage(doc1.Pages(2))
            End If

            ' save pdf document
            Dim pdf As Byte() = doc.Save()

            ' close pdf document
            doc.Close()

            ' return resulted pdf document
            Dim fileResult As FileResult = New FileContentResult(pdf, "application/pdf")
            fileResult.FileDownloadName = "Document.pdf"
            Return fileResult
        End Function
    End Class
End Namespace