Private Sub createPdfButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles createPdfButton.Click
    ' 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)

    Cursor = Cursors.WaitCursor

    ' The output PDF file
    Dim outPdfFile As String = "DemoAppFiles\Output\PDF_Creator\Create_PDF_Documents.pdf"
    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()

        ' Write the memory buffer in a PDF file
        System.IO.File.WriteAllBytes(outPdfFile, outPdfBuffer)
    Catch ex As Exception
        ' The PDF creation failed
        MessageBox.Show(String.Format("Create PDF Document Error. {0}", ex.Message))
        Return
    Finally
        ' Close the PDF document
        pdfDocument.Close()

        Cursor = Cursors.Arrow
    End Try

    ' Open the created PDF document in default PDF viewer
    Try
        Process.Start(outPdfFile)
    Catch ex As Exception
        MessageBox.Show(String.Format("Cannot open created PDF file '{0}'. {1}", outPdfFile, ex.Message))
    End Try
End Sub