Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.Configuration
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports SelectPdf

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

        Protected Sub BtnCreatePdf_Click(sender As Object, e As EventArgs)

            Dim renderingEngine As RenderingEngine = CType([Enum].Parse(GetType(RenderingEngine), DdlRenderingEngine.SelectedValue, True), RenderingEngine)
            ' read parameters from the webpage
            Dim url1 As String = TxtUrl1.Text
            Dim url2 As String = TxtUrl2.Text
            Dim url3 As String = TxtUrl3.Text

            ' 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)
            html1.RenderingEngine = renderingEngine
            html1.CefEnginePath = Server.MapPath(ConfigurationManager.AppSettings("CefEnginePath"))

            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)
            html2.RenderingEngine = renderingEngine
            html2.CefEnginePath = Server.MapPath(ConfigurationManager.AppSettings("CefEnginePath"))

            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)
            html3.RenderingEngine = renderingEngine
            html3.CefEnginePath = Server.MapPath(ConfigurationManager.AppSettings("CefEnginePath"))

            result = page3.Add(html3)

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

            ' close pdf document
            doc.Close()

        End Sub
    End Class
End Namespace
