Protected Sub createPdfButton_Click(ByVal sender As Object, ByVal e As EventArgs)
    ' Get the PDF Standard
    ' By default the Full PDF standard is used
    Dim pdfStandard As PdfStandardSubset = PdfStandardSubset.Full
    If pdfARadioButton.Checked Then
        pdfStandard = PdfStandardSubset.Pdf_A_1b
    ElseIf pdfXRadioButton.Checked Then
        pdfStandard = PdfStandardSubset.Pdf_X_1a
    End If

    ' Get the Color Space
    ' By default the RGB color space is used
    Dim pdfColorSpace As ColorSpace = ColorSpace.RGB
    If grayScaleRadioButton.Checked Then
        pdfColorSpace = ColorSpace.Gray
    ElseIf cmykRadioButton.Checked Then
        pdfColorSpace = ColorSpace.CMYK
    End If

    ' Create the PDF document
    Dim pdfDocument As Document = Nothing

    If pdfStandard = PdfStandardSubset.Full AndAlso pdfColorSpace = ColorSpace.RGB Then
        ' Create a PDF document with default standard and color space
        pdfDocument = New Document()
    Else
        ' Create a PDF document with the selected standard and color space
        pdfDocument = New Document(pdfStandard, pdfColorSpace)
    End If

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

    ' Get the selected PDF page size
    Dim pdfPageSize As PdfPageSize = SelectedPdfPageSize()

    ' Get the selected PDF page orientation
    Dim pdfPageOrientation As PdfPageOrientation = SelectedPdfPageOrientation()

    ' Get the PDF page margins
    Dim pdfPageMargins As New Margins(Single.Parse(leftMarginTextBox.Text), Single.Parse(rightMarginTextBox.Text), Single.Parse(topMarginTextBox.Text), Single.Parse(bottomMarginTextBox.Text))

    ' Create a PDF page in PDF document
    Dim firstPdfPage As PdfPage = pdfDocument.AddPage(pdfPageSize, pdfPageMargins, pdfPageOrientation)

    Try
        ' The URL of the HTML page to convert to PDF
        Dim urlToConvert As String = "http://www.winnovative-software.com"

        ' Create the HTML to PDF element
        Dim htmlToPdfElement As New HtmlToPdfElement(urlToConvert)

        ' Optionally set a delay before conversion to allow asynchonous scripts to finish
        htmlToPdfElement.ConversionDelay = 2

        ' Add the HTML to PDF element to PDF document
        firstPdfPage.AddElement(htmlToPdfElement)

        ' 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=Create_PDF_Documents.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
        pdfDocument.Close()
    End Try
End Sub