private void convertToPdfButton_Click(object sender, EventArgs e) { // Create a PDF document Document pdfDocument = new Document(); // 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="; // Add a page to PDF document PdfPage pdfPage = pdfDocument.AddPage(); Cursor = Cursors.WaitCursor; string outPdfFile = @"DemoAppFiles\Output\PDF_Creator\Digital_Signatures.pdf"; try { string htmlWithDigitalSignatureMarker = htmlStringTextBox.Text; string baseUrl = baseUrlTextBox.Text; // Add a HTML string with a marker for digital signature to PDF document HtmlToPdfElement htmlToPdfElement = new HtmlToPdfElement(htmlWithDigitalSignatureMarker, baseUrl); pdfPage.AddElement(htmlToPdfElement); // Make the HTML element with 'digital_signature_element' mapping ID a link to digital signature properties HtmlElementMapping digitalSignatureMapping = htmlToPdfElement.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("digital_signature_element"); if (digitalSignatureMapping != null) { PdfPage digitalSignaturePage = digitalSignatureMapping.PdfRectangles[0].PdfPage; RectangleF digitalSignatureRectangle = digitalSignatureMapping.PdfRectangles[0].Rectangle; string certificateFilePath = @"DemoAppFiles\Input\Certificates\wnvpdf.pfx"; // Get the certificate from password protected PFX file DigitalCertificatesCollection certificates = DigitalCertificatesStore.GetCertificates(certificateFilePath, "wnvpdf"); DigitalCertificate certificate = certificates[0]; // Create the digital signature DigitalSignatureElement signature = new DigitalSignatureElement(digitalSignatureRectangle, certificate); signature.Reason = "Protect the document from unwanted changes"; signature.ContactInfo = "The contact email is support@winnovative-software.com"; signature.Location = "Development server"; digitalSignaturePage.AddElement(signature); } // Save the PDF document in a memory buffer byte[] outPdfBuffer = pdfDocument.Save(); // Write the memory buffer in a PDF file System.IO.File.WriteAllBytes(outPdfFile, outPdfBuffer); } catch (Exception ex) { // 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; } // Open the created PDF document in default PDF viewer try { System.Diagnostics.Process.Start(outPdfFile); } catch (Exception ex) { MessageBox.Show(String.Format("Cannot open created PDF file '{0}'. {1}", outPdfFile, ex.Message)); } }