Protected Sub convertToPdfButton_Click(ByVal sender As Object, ByVal e As EventArgs)
    ' Create a HTML to PDF converter object with default settings
    Dim htmlToPdfConverter As New HtmlToPdfConverter()

    ' Set license key received after purchase to use the converter in licensed mode
    ' Leave it not set to use the converter in demo mode
    htmlToPdfConverter.LicenseKey = "fvDh8eDx4fHg4P/h8eLg/+Dj/+jo6Og="

    Dim pdfDocument As Document = Nothing
    Try
        ' Convert HTML page or string with mapping attributes to a PDF document object 
        ' The document can be further modified to highlight the selected elements
        If convertHtmlRadioButton.Checked Then
            Dim htmlWithMappingAttributes As String = htmlStringTextBox.Text
            Dim baseUrl As String = baseUrlTextBox.Text

            ' Convert a HTML string with mapping attributes to a PDF document object
            pdfDocument = htmlToPdfConverter.ConvertHtmlToPdfDocumentObject(htmlWithMappingAttributes, baseUrl)
        Else
            Dim url As String = urlTextBox.Text

            ' Convert a HTML page with mapping attributes to a PDF document object
            pdfDocument = htmlToPdfConverter.ConvertUrlToPdfDocumentObject(url)
        End If

        ' Display detailed information about the selected elements
        Dim htmlElementInfoBuilder As New StringBuilder()
        For Each htmlElementInfo As HtmlElementMapping In htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult
            ' Get other information about HTML element
            Dim htmlElementTagName As String = htmlElementInfo.HtmlElementTagName
            Dim htmlElementID As String = htmlElementInfo.HtmlElementId
            Dim htmlElementMappingID As String = htmlElementInfo.MappingId
            Dim htmlElementCssClasssName As String = htmlElementInfo.HtmlElementCssClassName
            Dim htmlElementHtmlCode As String = htmlElementInfo.HtmlElementOuterHtml
            Dim htmlElementInnerHtml As String = htmlElementInfo.HtmlElementInnerHtml
            Dim htmlElementText As String = htmlElementInfo.HtmlElementText
            Dim htmlElementAttributes As System.Collections.Specialized.NameValueCollection = htmlElementInfo.HtmlElementAttributes
            Dim htmlElementRectanglesInPdf() As HtmlElementPdfRectangle = htmlElementInfo.PdfRectangles

            htmlElementInfoBuilder.AppendFormat("<br/>---------------------------------------- HTML Element Info ----------------------------------------<br/><br/>")
            htmlElementInfoBuilder.AppendFormat("<b>Tag Name:</b> {0}<br/>", htmlElementTagName)
            htmlElementInfoBuilder.AppendFormat("<b>Element ID:</b> {0}<br/>", htmlElementID)
            htmlElementInfoBuilder.AppendFormat("<b>Mapping ID:</b> {0}<br/>", htmlElementMappingID)
            htmlElementInfoBuilder.AppendFormat("<b>Text:</b> {0}<br/>", htmlElementText)

            htmlElementInfoBuilder.AppendFormat("<b>Attributes:</b><br/>")
            For i As Integer = 0 To htmlElementAttributes.Count - 1
                htmlElementInfoBuilder.AppendFormat("&nbsp;&nbsp;&nbsp;{0} = ""{1}""<br/>", htmlElementAttributes.GetKey(i), htmlElementAttributes.Get(i))
            Next i


            htmlElementInfoBuilder.AppendFormat("<b>Location in PDF:</b><br/>")
            For i As Integer = 0 To htmlElementRectanglesInPdf.Length - 1
                Dim pdfPage As PdfPage = htmlElementRectanglesInPdf(i).PdfPage
                Dim pdfPageIndex As Integer = htmlElementRectanglesInPdf(i).PageIndex
                Dim rectangleInPdfPage As RectangleF = htmlElementRectanglesInPdf(i).Rectangle

                htmlElementInfoBuilder.AppendFormat("&nbsp;&nbsp;&nbsp;PDF Page Index: {0}<br>", pdfPageIndex)
                htmlElementInfoBuilder.AppendFormat("&nbsp;&nbsp;&nbsp;Rectangle: X = {0:N2} pt , Y = {1:N2} pt , W = {2:N2} pt , H = {3:N2} pt<br/>", rectangleInPdfPage.X, rectangleInPdfPage.Y, rectangleInPdfPage.Width, rectangleInPdfPage.Height)
            Next i

            htmlElementInfoBuilder.AppendFormat("<br/>")
        Next htmlElementInfo

        Dim lastPdfPage As PdfPage = htmlToPdfConverter.ConversionSummary.LastPdfPage
        Dim lastPageRectangle As RectangleF = htmlToPdfConverter.ConversionSummary.LastPageRectangle

        Dim htmlElementInfoHtml As New HtmlToPdfElement(0, lastPageRectangle.Bottom + 1, htmlElementInfoBuilder.ToString(), Nothing)
        lastPdfPage.AddElement(htmlElementInfoHtml)

        ' Save the PDF document in a memory buffer
        Dim outPdfBuffer() As Byte = pdfDocument.Save()

        ' Send the PDF as response to browser

        ' Set response content type
        Response.AddHeader("Content-Type", "application/pdf")

        ' Instruct the browser to open the PDF file as an attachment or inline
        Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Select_in_HTML_Elements_to_Retrieve.pdf; size={0}", outPdfBuffer.Length.ToString()))

        ' Write the PDF document buffer to HTTP response
        Response.BinaryWrite(outPdfBuffer)

        ' End the HTTP response and stop the current page processing
        Response.End()
    Finally
        ' Close the PDF document
        If pdfDocument IsNot Nothing Then
            pdfDocument.Close()
        End If
    End Try
End Sub