SelectPdf for .NET - Convert Multiple Urls into the same Pdf Document - VB.NET / ASP.NET MVC Sample

This sample shows how to convert 3 different urls to the same pdf document using SelectPdf Pdf Library for .NET.

Url 1: 

Url 2: 

Url 3: 

Sample Code VB.NET

Imports SelectPdf

Namespace Controllers
    Public Class ConvertMultipleUrlsToPdfController
        Inherits Controller

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

        Public Function SubmitAction(collection As FormCollection) As ActionResult
            ' read parameters from the webpage
            Dim url1 As String = collection("TxtUrl1")
            Dim url2 As String = collection("TxtUrl2")
            Dim url3 As String = collection("TxtUrl3")

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

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

            ' add the first url
            Dim html1 As New PdfHtmlElement(url1)
            Dim result As PdfRenderingResult = page.Add(html1)

            ' get the last page of the previous conversion
            Dim page2 As PdfPage = doc.Pages(result.PdfPageLastIndex)

            ' add the second url
            Dim html2 As New PdfHtmlElement(result.PdfPageLastRectangle.Left,
                                            result.PdfPageLastRectangle.Bottom, url2)
            result = page2.Add(html2)

            ' get the last page of the previous conversion
            Dim page3 As PdfPage = doc.Pages(result.PdfPageLastIndex)

            ' add the third url
            Dim html3 As New PdfHtmlElement(result.PdfPageLastRectangle.Left,
                                            result.PdfPageLastRectangle.Bottom, url3)
            result = page3.Add(html3)

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

            ' close pdf document

            ' 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