Beispiel #1
0
        protected void convertToPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create a HTML to PDF converter object with default settings
            HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                htmlToPdfConverter.ServicePassword = textBoxServicePassword.Text;
            }

            // 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 = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed
            // Set this property to 0 if you don't need to wait for such asynchcronous operations to finish
            htmlToPdfConverter.ConversionDelay = 2;

            string htmlWithLinksAndAttachMarkers = htmlStringTextBox.Text;
            string baseUrl = baseUrlTextBox.Text;

            // Convert a HTML string with markers for file links and attachments to a PDF document object
            Document pdfDocument = htmlToPdfConverter.ConvertHtmlToPdfDocumentObject(htmlWithLinksAndAttachMarkers, baseUrl);

            // Make the HTML element with 'text_note' mapping ID a text note
            HtmlElementMapping textNoteMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("text_note");

            if (textNoteMapping != null)
            {
                PdfPage        textNotePage      = pdfDocument.GetPage(textNoteMapping.PdfRectangles[0].PageIndex);
                RectangleFloat textNoteRectangle = textNoteMapping.PdfRectangles[0].Rectangle;

                // Create the text note
                TextNoteElement textNoteElement = new TextNoteElement(textNoteRectangle, "This is an initially closed text note");
                textNoteElement.NoteIcon = TextNoteIcon.Note;
                textNoteElement.Open     = false;
                textNotePage.AddElement(textNoteElement);
            }

            // Make the HTML element with 'text_note_opened' mapping ID an initially opened text note
            HtmlElementMapping textNoteOpenedMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("text_note_opened");

            if (textNoteOpenedMapping != null)
            {
                PdfPage        textNoteOpenedPage      = pdfDocument.GetPage(textNoteMapping.PdfRectangles[0].PageIndex);
                RectangleFloat textNoteOpenedRectangle = textNoteOpenedMapping.PdfRectangles[0].Rectangle;

                // Create the text note
                TextNoteElement textNoteOpenedElement = new TextNoteElement(textNoteOpenedRectangle, "This is an initially opened text note");
                textNoteOpenedElement.NoteIcon = TextNoteIcon.Note;
                textNoteOpenedElement.Open     = true;
                textNoteOpenedPage.AddElement(textNoteOpenedElement);
            }

            // Make the HTML element with 'help_note' mapping ID a help note
            HtmlElementMapping helpNoteMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("help_note");

            if (helpNoteMapping != null)
            {
                PdfPage        helpNotePage      = pdfDocument.GetPage(textNoteMapping.PdfRectangles[0].PageIndex);
                RectangleFloat helpNoteRectangle = helpNoteMapping.PdfRectangles[0].Rectangle;

                // Create the text note
                TextNoteElement helpNoteElement = new TextNoteElement(helpNoteRectangle, "This is an initially closed help note");
                helpNoteElement.NoteIcon = TextNoteIcon.Help;
                helpNoteElement.Open     = false;
                helpNotePage.AddElement(helpNoteElement);
            }

            // Make the HTML element with 'help_note_opened' mapping ID an initially opened help note
            HtmlElementMapping helpNoteOpenedMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("help_note_opened");

            if (helpNoteOpenedMapping != null)
            {
                PdfPage        helpNoteOpenedPage      = pdfDocument.GetPage(textNoteMapping.PdfRectangles[0].PageIndex);
                RectangleFloat helpNoteOpenedRectangle = helpNoteOpenedMapping.PdfRectangles[0].Rectangle;

                // Create the text note
                TextNoteElement helpNoteOpenedElement = new TextNoteElement(helpNoteOpenedRectangle, "This is an initially opened help note");
                helpNoteOpenedElement.NoteIcon = TextNoteIcon.Help;
                helpNoteOpenedElement.Open     = true;
                helpNoteOpenedPage.AddElement(helpNoteOpenedElement);
            }

            // Make the HTML element with 'comment_note' mapping ID a comment note
            HtmlElementMapping commentNoteMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("comment_note");

            if (commentNoteMapping != null)
            {
                PdfPage        commentNotePage      = pdfDocument.GetPage(textNoteMapping.PdfRectangles[0].PageIndex);
                RectangleFloat commentNoteRectangle = commentNoteMapping.PdfRectangles[0].Rectangle;

                // Create the text note
                TextNoteElement commentNoteElement = new TextNoteElement(commentNoteRectangle, "This is an initially closed comment note");
                commentNoteElement.NoteIcon = TextNoteIcon.Comment;
                commentNoteElement.Open     = false;
                commentNotePage.AddElement(commentNoteElement);
            }

            // Make the HTML element with 'comment_note_opened' mapping ID an initially opened comment note
            HtmlElementMapping commentNoteOpenedMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("comment_note_opened");

            if (commentNoteOpenedMapping != null)
            {
                PdfPage        commentNoteOpenedPage      = pdfDocument.GetPage(textNoteMapping.PdfRectangles[0].PageIndex);
                RectangleFloat commentNoteOpenedRectangle = commentNoteOpenedMapping.PdfRectangles[0].Rectangle;

                // Create the text note
                TextNoteElement commentNoteOpenedElement = new TextNoteElement(commentNoteOpenedRectangle, "This is an initially opened comment note");
                commentNoteOpenedElement.NoteIcon = TextNoteIcon.Comment;
                commentNoteOpenedElement.Open     = true;
                commentNoteOpenedPage.AddElement(commentNoteOpenedElement);
            }

            // Make the HTML element with 'paragraph_note' mapping ID a paragraph note
            HtmlElementMapping paragraphNoteMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("paragraph_note");

            if (paragraphNoteMapping != null)
            {
                PdfPage        paragraphNotePage      = pdfDocument.GetPage(textNoteMapping.PdfRectangles[0].PageIndex);
                RectangleFloat paragraphNoteRectangle = paragraphNoteMapping.PdfRectangles[0].Rectangle;

                // Create the text note
                TextNoteElement paragraphNoteElement = new TextNoteElement(paragraphNoteRectangle, "This is an initially closed paragraph note");
                paragraphNoteElement.NoteIcon = TextNoteIcon.Paragraph;
                paragraphNoteElement.Open     = false;
                paragraphNotePage.AddElement(paragraphNoteElement);
            }

            // Make the HTML element with 'new_paragraph_note' mapping ID a new paragraph note
            HtmlElementMapping newParagraphNoteMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("new_paragraph_note");

            if (newParagraphNoteMapping != null)
            {
                PdfPage        newParagraphNotePage      = pdfDocument.GetPage(textNoteMapping.PdfRectangles[0].PageIndex);
                RectangleFloat newParagraphNoteRectangle = newParagraphNoteMapping.PdfRectangles[0].Rectangle;

                // Create the text note
                TextNoteElement newParagraphNoteElement = new TextNoteElement(newParagraphNoteRectangle, "This is an initially closed new paragraph note");
                newParagraphNoteElement.NoteIcon = TextNoteIcon.NewParagraph;
                newParagraphNoteElement.Open     = false;
                newParagraphNotePage.AddElement(newParagraphNoteElement);
            }

            // Make the HTML element with 'key_note' mapping ID a key note
            HtmlElementMapping keyNoteMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("key_note");

            if (keyNoteMapping != null)
            {
                PdfPage        keyNotePage      = pdfDocument.GetPage(textNoteMapping.PdfRectangles[0].PageIndex);
                RectangleFloat keyNoteRectangle = keyNoteMapping.PdfRectangles[0].Rectangle;

                // Create the text note
                TextNoteElement keyNoteElement = new TextNoteElement(keyNoteRectangle, "This is an initially closed key note");
                keyNoteElement.NoteIcon = TextNoteIcon.Key;
                keyNoteElement.Open     = false;
                keyNotePage.AddElement(keyNoteElement);
            }

            // Save the PDF document in a memory buffer
            byte[] outPdfBuffer = 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=Text_Notes.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();
        }
Beispiel #2
0
        public ActionResult ConvertHtmlToPdf(IFormCollection collection)
        {
            // Create a HTML to PDF converter object with default settings
            HtmlToPdfConverter htmlToPdfConverter = 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 = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed
            // Set this property to 0 if you don't need to wait for such asynchcronous operations to finish
            htmlToPdfConverter.ConversionDelay = 2;

            Document pdfDocument = null;

            try
            {
                string htmlWithButton = collection["htmlStringTextBox"];
                string baseUrl        = collection["baseUrlTextBox"];

                // Convert a HTML string with a button to a PDF document object
                pdfDocument = htmlToPdfConverter.ConvertHtmlToPdfDocumentObject(htmlWithButton, baseUrl);

                // Get the button location in PDF
                HtmlElementMapping buttonMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("javascript_button");
                if (buttonMapping != null)
                {
                    PdfPage    buttonPdfPage   = buttonMapping.PdfRectangles[0].PdfPage;
                    RectangleF buttonRectangle = buttonMapping.PdfRectangles[0].Rectangle;

                    // The font used for buttons text in PDF document
                    PdfFont buttonTextFont = pdfDocument.AddFont(new Font("Times New Roman", 8, FontStyle.Regular, GraphicsUnit.Point));

                    // Create a PDF form button
                    PdfFormButton pdfButton = pdfDocument.Form.AddButton(buttonPdfPage, buttonRectangle, "Execute Acrobat JavaScript", buttonTextFont);

                    // Set JavaScript action to be executed when the button is clicked
                    string javaScript = null;
                    if (collection["JavaScriptAction"] == "alertMessageRadioButton")
                    {
                        // JavaScript to display an alert mesage
                        javaScript = String.Format("app.alert(\"{0}\")", collection["alertMessageTextBox"]);
                    }
                    else if (collection["JavaScriptAction"] == "printDialogRadioButton")
                    {
                        // JavaScript to open the print dialog
                        javaScript = "print()";
                    }
                    else if (collection["JavaScriptAction"] == "zoomLevelRadioButton")
                    {
                        // JavaScript to set an initial zoom level
                        javaScript = String.Format("zoom={0}", int.Parse(collection["zoomLevelTextBox"]));
                    }

                    // Set the JavaScript action
                    pdfButton.Action = new PdfActionJavaScript(javaScript);
                }

                // Save the PDF document in a memory buffer
                byte[] outPdfBuffer = pdfDocument.Save();

                // Send the PDF file to browser
                FileResult fileResult = new FileContentResult(outPdfBuffer, "application/pdf");
                fileResult.FileDownloadName = "Button_JavaScript_Actions.pdf";

                return(fileResult);
            }
            finally
            {
                // Close the PDF document
                if (pdfDocument != null)
                {
                    pdfDocument.Close();
                }
            }
        }
Beispiel #3
0
        protected void convertToPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create a HTML to PDF converter object with default settings
            HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                htmlToPdfConverter.ServicePassword = textBoxServicePassword.Text;
            }

            // 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 = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed
            // Set this property to 0 if you don't need to wait for such asynchcronous operations to finish
            htmlToPdfConverter.ConversionDelay = 2;

            string htmlWithLinksAndAttachMarkers = htmlStringTextBox.Text;
            string baseUrl = baseUrlTextBox.Text;

            // Convert a HTML string with markers for file links and attachments to a PDF document object
            Document pdfDocument = htmlToPdfConverter.ConvertHtmlToPdfDocumentObject(htmlWithLinksAndAttachMarkers, baseUrl);

            // Display the attachments panel when the PDF document is opened in a PDF viewer
            pdfDocument.ViewerPreferences.PageMode = ViewerPageMode.UseAttachments;

            // Create File Attachments

            // Create an attachment from a file without icon
            string fileAttachmentPath = Server.MapPath("~/DemoAppFiles/Input/Attach_Files/Attachment_File.txt");

            pdfDocument.AddFileAttachment(fileAttachmentPath, "Attachment from File");

            // Create an attachment from a stream without icon
            string fileStreamAttachmentPath = Server.MapPath("~/DemoAppFiles/Input/Attach_Files/Attachment_Stream.txt");

            byte[] attachmentData = System.IO.File.ReadAllBytes(fileStreamAttachmentPath);
            pdfDocument.AddFileAttachment(attachmentData, "Attachment_Stream.txt", "Attachment from Stream");

            // Create an attachment from file with paperclip icon in PDF
            HtmlElementMapping attachFromFileIconMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("attach_from_file_icon");

            if (attachFromFileIconMapping != null)
            {
                PdfPage        attachFromFilePage          = pdfDocument.GetPage(attachFromFileIconMapping.PdfRectangles[0].PageIndex);
                RectangleFloat attachFromFileIconRectangle = attachFromFileIconMapping.PdfRectangles[0].Rectangle;

                string fileAttachmentWithIconPath = Server.MapPath("~/DemoAppFiles/Input/Attach_Files/Attachment_File_Icon.txt");

                // Create the attachment from file
                FileAttachmentElement attachFromFileElement = new FileAttachmentElement(attachFromFileIconRectangle, fileAttachmentWithIconPath);
                attachFromFileElement.IconType  = FileAttachmentIcon.Paperclip;
                attachFromFileElement.Text      = "Attachment from File with Paperclip Icon";
                attachFromFileElement.IconColor = RgbColor.Blue;
                attachFromFilePage.AddElement(attachFromFileElement);
            }

            // Create an attachment from stream with pushpin icon in PDF
            byte[]             attachmentDataWithIcon      = null;
            HtmlElementMapping attachFromStreamIconMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("attach_from_stream_icon");

            if (attachFromStreamIconMapping != null)
            {
                PdfPage        attachFromStreamPage          = pdfDocument.GetPage(attachFromStreamIconMapping.PdfRectangles[0].PageIndex);
                RectangleFloat attachFromStreamIconRectangle = attachFromStreamIconMapping.PdfRectangles[0].Rectangle;

                string fileStreamAttachmentWithIconPath = Server.MapPath("~/DemoAppFiles/Input/Attach_Files/Attachment_Stream_Icon.txt");

                attachmentDataWithIcon = System.IO.File.ReadAllBytes(fileStreamAttachmentWithIconPath);

                // Create the attachment from stream
                FileAttachmentElement attachFromStreamElement = new FileAttachmentElement(attachFromStreamIconRectangle, attachmentDataWithIcon, "Attachment_Stream_Icon.txt");
                attachFromStreamElement.IconType  = FileAttachmentIcon.PushPin;
                attachFromStreamElement.Text      = "Attachment from Stream with Pushpin Icon";
                attachFromStreamElement.IconColor = RgbColor.Green;
                attachFromStreamPage.AddElement(attachFromStreamElement);
            }

            // Save the PDF document in a memory buffer
            byte[] outPdfBuffer = 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=File_Links_and_Attachments.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();
        }
Beispiel #4
0
        protected void convertToPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create a HTML to PDF converter object with default settings
            HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                htmlToPdfConverter.ServicePassword = textBoxServicePassword.Text;
            }

            // 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 = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed
            // Set this property to 0 if you don't need to wait for such asynchcronous operations to finish
            htmlToPdfConverter.ConversionDelay = 2;

            string htmlWithButton = htmlStringTextBox.Text;
            string baseUrl        = baseUrlTextBox.Text;

            // Convert a HTML string with a button to a PDF document object
            Document pdfDocument = htmlToPdfConverter.ConvertHtmlToPdfDocumentObject(htmlWithButton, baseUrl);

            // Get the button location in PDF
            HtmlElementMapping buttonMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("javascript_button");

            if (buttonMapping != null)
            {
                PdfPage        buttonPdfPage   = pdfDocument.GetPage(buttonMapping.PdfRectangles[0].PageIndex);
                RectangleFloat buttonRectangle = buttonMapping.PdfRectangles[0].Rectangle;

                // The font used for buttons text in PDF document
                PdfFont buttonTextFont = new PdfFont("Times New Roman", 8, true);

                // Create a PDF form button
                PdfFormButton pdfButton = new PdfFormButton(buttonRectangle, "Execute Acrobat JavaScript", buttonTextFont);
                pdfButton.Style.BackColor = RgbColor.Beige;
                pdfDocument.Form.AddButton(buttonPdfPage, pdfButton);

                // Set JavaScript action to be executed when the button is clicked
                string javaScript = null;
                if (alertMessageRadioButton.Checked)
                {
                    // JavaScript to display an alert mesage
                    javaScript = String.Format("app.alert(\"{0}\")", alertMessageTextBox.Text);
                }
                else if (printDialogRadioButton.Checked)
                {
                    // JavaScript to open the print dialog
                    javaScript = "print()";
                }
                else if (zoomLevelRadioButton.Checked)
                {
                    // JavaScript to set an initial zoom level
                    javaScript = String.Format("zoom={0}", int.Parse(zoomLevelTextBox.Text));
                }

                // Set the JavaScript action
                pdfButton.Action = new PdfActionJavaScript(javaScript);
            }

            // Save the PDF document in a memory buffer
            byte[] outPdfBuffer = 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=Button_JavaScript_Actions.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();
        }
        public ActionResult ConvertHtmlToPdf(IFormCollection collection)
        {
            // Create a HTML to PDF converter object with default settings
            HtmlToPdfConverter htmlToPdfConverter = 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 = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed
            // Set this property to 0 if you don't need to wait for such asynchcronous operations to finish
            htmlToPdfConverter.ConversionDelay = 2;

            Document pdfDocument = null;

            try
            {
                string htmlWithDigitalSignatureMarker = collection["htmlStringTextBox"];
                string baseUrl = collection["baseUrlTextBox"];

                // Convert a HTML string with a marker for digital signature to a PDF document object
                pdfDocument = htmlToPdfConverter.ConvertHtmlToPdfDocumentObject(htmlWithDigitalSignatureMarker, baseUrl);

                // Make the HTML element with 'digital_signature_element' mapping ID a link to digital signature properties
                HtmlElementMapping digitalSignatureMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("digital_signature_element");
                if (digitalSignatureMapping != null)
                {
                    PdfPage    digitalSignaturePage      = digitalSignatureMapping.PdfRectangles[0].PdfPage;
                    RectangleF digitalSignatureRectangle = digitalSignatureMapping.PdfRectangles[0].Rectangle;

                    string certificateFilePath = m_hostingEnvironment.ContentRootPath + "/wwwroot" + "/DemoAppFiles/Input/Certificates/evopdf.pfx";

                    // Get the certificate from password protected PFX file
                    DigitalCertificatesCollection certificates = DigitalCertificatesStore.GetCertificates(certificateFilePath, "evopdf");
                    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 [email protected]";
                    signature.Location    = "Development server";
                    digitalSignaturePage.AddElement(signature);
                }

                // Save the PDF document in a memory buffer
                byte[] outPdfBuffer = pdfDocument.Save();

                // Send the PDF file to browser
                FileResult fileResult = new FileContentResult(outPdfBuffer, "application/pdf");
                fileResult.FileDownloadName = "Digital_Signatures.pdf";

                return(fileResult);
            }
            finally
            {
                // Close the PDF document
                if (pdfDocument != null)
                {
                    pdfDocument.Close();
                }
            }
        }
        protected void convertToPdfButton_Click(object sender, EventArgs e)
        {
            // Create a HTML to PDF converter object with default settings
            HtmlToPdfConverter htmlToPdfConverter = 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 = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed
            // Set this property to 0 if you don't need to wait for such asynchcronous operations to finish
            htmlToPdfConverter.ConversionDelay = 2;

            Document pdfDocument = null;

            try
            {
                string htmlWithDigitalSignatureMarker = htmlStringTextBox.Text;
                string baseUrl = baseUrlTextBox.Text;

                // Convert a HTML string with a marker for digital signature to a PDF document object
                pdfDocument = htmlToPdfConverter.ConvertHtmlToPdfDocumentObject(htmlWithDigitalSignatureMarker, baseUrl);

                // Make the HTML element with 'digital_signature_element' mapping ID a link to digital signature properties
                HtmlElementMapping digitalSignatureMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("digital_signature_element");
                if (digitalSignatureMapping != null)
                {
                    PdfPage    digitalSignaturePage      = digitalSignatureMapping.PdfRectangles[0].PdfPage;
                    RectangleF digitalSignatureRectangle = digitalSignatureMapping.PdfRectangles[0].Rectangle;

                    string certificateFilePath = Server.MapPath("~/DemoAppFiles/Input/Certificates/evopdf.pfx");

                    // Get the certificate from password protected PFX file
                    DigitalCertificatesCollection certificates = DigitalCertificatesStore.GetCertificates(certificateFilePath, "evopdf");
                    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 [email protected]";
                    signature.Location    = "Development server";
                    digitalSignaturePage.AddElement(signature);
                }

                // Save the PDF document in a memory buffer
                byte[] outPdfBuffer = 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=Digital_Signatures.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 != null)
                {
                    pdfDocument.Close();
                }
            }
        }
        public ActionResult ConvertHtmlToPdf(IFormCollection collection)
        {
            // Create a HTML to PDF converter object with default settings
            HtmlToPdfConverter htmlToPdfConverter = 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 = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed
            // Set this property to 0 if you don't need to wait for such asynchcronous operations to finish
            htmlToPdfConverter.ConversionDelay = 2;

            Document pdfDocument = null;

            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 (collection["HtmlPageSource"] == "convertHtmlRadioButton")
                {
                    string htmlWithMappingAttributes = collection["htmlStringTextBox"];
                    string baseUrl = collection["baseUrlTextBox"];

                    // Convert a HTML string with mapping attributes to a PDF document object
                    pdfDocument = htmlToPdfConverter.ConvertHtmlToPdfDocumentObject(htmlWithMappingAttributes, baseUrl);
                }
                else
                {
                    string url = collection["urlTextBox"];

                    // Convert a HTML page with mapping attributes to a PDF document object
                    pdfDocument = htmlToPdfConverter.ConvertUrlToPdfDocumentObject(url);
                }

                // Display detailed information about the selected elements
                StringBuilder htmlElementInfoBuilder = new StringBuilder();
                foreach (HtmlElementMapping htmlElementInfo in htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult)
                {
                    // Get other information about HTML element
                    string htmlElementTagName       = htmlElementInfo.HtmlElementTagName;
                    string htmlElementID            = htmlElementInfo.HtmlElementId;
                    string htmlElementMappingID     = htmlElementInfo.MappingId;
                    string htmlElementCssClasssName = htmlElementInfo.HtmlElementCssClassName;
                    string htmlElementHtmlCode      = htmlElementInfo.HtmlElementOuterHtml;
                    string htmlElementInnerHtml     = htmlElementInfo.HtmlElementInnerHtml;
                    string htmlElementText          = htmlElementInfo.HtmlElementText;
                    System.Collections.Specialized.NameValueCollection htmlElementAttributes = htmlElementInfo.HtmlElementAttributes;
                    HtmlElementPdfRectangle[] htmlElementRectanglesInPdf = 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 (int i = 0; i < htmlElementAttributes.Count; i++)
                    {
                        htmlElementInfoBuilder.AppendFormat("&nbsp;&nbsp;&nbsp;{0} = \"{1}\"<br/>", htmlElementAttributes.GetKey(i), htmlElementAttributes.Get(i));
                    }


                    htmlElementInfoBuilder.AppendFormat("<b>Location in PDF:</b><br/>");
                    for (int i = 0; i < htmlElementRectanglesInPdf.Length; i++)
                    {
                        PdfPage    pdfPage            = htmlElementRectanglesInPdf[i].PdfPage;
                        int        pdfPageIndex       = htmlElementRectanglesInPdf[i].PageIndex;
                        RectangleF rectangleInPdfPage = 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);
                    }

                    htmlElementInfoBuilder.AppendFormat("<br/>");
                }

                PdfPage    lastPdfPage       = htmlToPdfConverter.ConversionSummary.LastPdfPage;
                RectangleF lastPageRectangle = htmlToPdfConverter.ConversionSummary.LastPageRectangle;

                HtmlToPdfElement htmlElementInfoHtml = new HtmlToPdfElement(0, lastPageRectangle.Bottom + 1, htmlElementInfoBuilder.ToString(), null);
                lastPdfPage.AddElement(htmlElementInfoHtml);

                // Save the PDF document in a memory buffer
                byte[] outPdfBuffer = pdfDocument.Save();

                // Send the PDF file to browser
                FileResult fileResult = new FileContentResult(outPdfBuffer, "application/pdf");
                fileResult.FileDownloadName = "Select_in_HTML_Elements_to_Retrieve.pdf";

                return(fileResult);
            }
            finally
            {
                // Close the PDF document
                if (pdfDocument != null)
                {
                    pdfDocument.Close();
                }
            }
        }
Beispiel #8
0
        public ActionResult ConvertHtmlToPdf(IFormCollection collection)
        {
            // Create a HTML to PDF converter object with default settings
            HtmlToPdfConverter htmlToPdfConverter = 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 = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed
            // Set this property to 0 if you don't need to wait for such asynchcronous operations to finish
            htmlToPdfConverter.ConversionDelay = 2;

            Document pdfDocument = null;

            try
            {
                string htmlWithLinksAndAttachMarkers = collection["htmlStringTextBox"];
                string baseUrl = collection["baseUrlTextBox"];

                // Convert a HTML string with markers for file links and attachments to a PDF document object
                pdfDocument = htmlToPdfConverter.ConvertHtmlToPdfDocumentObject(htmlWithLinksAndAttachMarkers, baseUrl);

                // Display the attachments panel when the PDF document is opened in a PDF viewer
                pdfDocument.ViewerPreferences.PageMode = ViewerPageMode.UseAttachments;

                // Create File Attachments

                // Create an attachment from a file without icon
                string fileAttachmentPath = m_hostingEnvironment.ContentRootPath + "/wwwroot" + "/DemoAppFiles/Input/Attach_Files/Attachment_File.txt";
                pdfDocument.AddFileAttachment(fileAttachmentPath, "Attachment from File");

                // Create an attachment from a stream without icon
                string fileStreamAttachmentPath       = m_hostingEnvironment.ContentRootPath + "/wwwroot" + "/DemoAppFiles/Input/Attach_Files/Attachment_Stream.txt";
                System.IO.FileStream attachmentStream = new System.IO.FileStream(fileStreamAttachmentPath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                pdfDocument.AddFileAttachment(attachmentStream, "Attachment_Stream.txt", "Attachment from Stream");

                // Create an attachment from file with paperclip icon in PDF
                HtmlElementMapping attachFromFileIconMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("attach_from_file_icon");
                if (attachFromFileIconMapping != null)
                {
                    PdfPage    attachFromFilePage          = attachFromFileIconMapping.PdfRectangles[0].PdfPage;
                    RectangleF attachFromFileIconRectangle = attachFromFileIconMapping.PdfRectangles[0].Rectangle;

                    string fileAttachmentWithIconPath = m_hostingEnvironment.ContentRootPath + "/wwwroot" + "/DemoAppFiles/Input/Attach_Files/Attachment_File_Icon.txt";

                    // Create the attachment from file
                    FileAttachmentElement attachFromFileElement = new FileAttachmentElement(attachFromFileIconRectangle, fileAttachmentWithIconPath);
                    attachFromFileElement.IconType  = FileAttachmentIcon.Paperclip;
                    attachFromFileElement.Text      = "Attachment from File with Paperclip Icon";
                    attachFromFileElement.IconColor = Color.Blue;
                    attachFromFilePage.AddElement(attachFromFileElement);
                }

                // Create an attachment from stream with pushpin icon in PDF
                System.IO.FileStream attachmentStreamWithIcon    = null;
                HtmlElementMapping   attachFromStreamIconMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("attach_from_stream_icon");
                if (attachFromStreamIconMapping != null)
                {
                    PdfPage    attachFromStreamPage          = attachFromStreamIconMapping.PdfRectangles[0].PdfPage;
                    RectangleF attachFromStreamIconRectangle = attachFromStreamIconMapping.PdfRectangles[0].Rectangle;

                    string fileStreamAttachmentWithIconPath = m_hostingEnvironment.ContentRootPath + "/wwwroot" + "/DemoAppFiles/Input/Attach_Files/Attachment_Stream_Icon.txt";

                    attachmentStreamWithIcon = new System.IO.FileStream(fileStreamAttachmentWithIconPath, System.IO.FileMode.Open, System.IO.FileAccess.Read);

                    // Create the attachment from stream
                    FileAttachmentElement attachFromStreamElement = new FileAttachmentElement(attachFromStreamIconRectangle, attachmentStreamWithIcon, "Attachment_Stream_Icon.txt");
                    attachFromStreamElement.IconType  = FileAttachmentIcon.PushPin;
                    attachFromStreamElement.Text      = "Attachment from Stream with Pushpin Icon";
                    attachFromStreamElement.IconColor = Color.Green;
                    attachFromStreamPage.AddElement(attachFromStreamElement);
                }

                // Save the PDF document in a memory buffer
                byte[] outPdfBuffer = pdfDocument.Save();

                // Send the PDF file to browser
                FileResult fileResult = new FileContentResult(outPdfBuffer, "application/pdf");
                fileResult.FileDownloadName = "File_Links_and_Attachments.pdf";

                return(fileResult);
            }
            finally
            {
                // Close the PDF document
                if (pdfDocument != null)
                {
                    pdfDocument.Close();
                }
            }
        }
        public ActionResult ConvertHtmlToPdf(IFormCollection collection)
        {
            // Create a HTML to PDF converter object with default settings
            HtmlToPdfConverter htmlToPdfConverter = 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 = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed
            // Set this property to 0 if you don't need to wait for such asynchcronous operations to finish
            htmlToPdfConverter.ConversionDelay = 2;

            Document pdfDocument = null;

            try
            {
                string htmlWithLinksAndAttachMarkers = collection["htmlStringTextBox"];
                string baseUrl = collection["baseUrlTextBox"];

                // Convert a HTML string with markers for file links and attachments to a PDF document object
                pdfDocument = htmlToPdfConverter.ConvertHtmlToPdfDocumentObject(htmlWithLinksAndAttachMarkers, baseUrl);

                // Make the HTML element with 'text_note' mapping ID a text note
                HtmlElementMapping textNoteMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("text_note");
                if (textNoteMapping != null)
                {
                    PdfPage    textNotePage      = textNoteMapping.PdfRectangles[0].PdfPage;
                    RectangleF textNoteRectangle = textNoteMapping.PdfRectangles[0].Rectangle;

                    // Create the text note
                    TextNoteElement textNoteElement = new TextNoteElement(textNoteRectangle, "This is an initially closed text note");
                    textNoteElement.NoteIcon = TextNoteIcon.Note;
                    textNoteElement.Open     = false;
                    textNotePage.AddElement(textNoteElement);
                }

                // Make the HTML element with 'text_note_opened' mapping ID an initially opened text note
                HtmlElementMapping textNoteOpenedMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("text_note_opened");
                if (textNoteOpenedMapping != null)
                {
                    PdfPage    textNoteOpenedPage      = textNoteOpenedMapping.PdfRectangles[0].PdfPage;
                    RectangleF textNoteOpenedRectangle = textNoteOpenedMapping.PdfRectangles[0].Rectangle;

                    // Create the text note
                    TextNoteElement textNoteOpenedElement = new TextNoteElement(textNoteOpenedRectangle, "This is an initially opened text note");
                    textNoteOpenedElement.NoteIcon = TextNoteIcon.Note;
                    textNoteOpenedElement.Open     = true;
                    textNoteOpenedPage.AddElement(textNoteOpenedElement);
                }

                // Make the HTML element with 'help_note' mapping ID a help note
                HtmlElementMapping helpNoteMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("help_note");
                if (helpNoteMapping != null)
                {
                    PdfPage    helpNotePage      = helpNoteMapping.PdfRectangles[0].PdfPage;
                    RectangleF helpNoteRectangle = helpNoteMapping.PdfRectangles[0].Rectangle;

                    // Create the text note
                    TextNoteElement helpNoteElement = new TextNoteElement(helpNoteRectangle, "This is an initially closed help note");
                    helpNoteElement.NoteIcon = TextNoteIcon.Help;
                    helpNoteElement.Open     = false;
                    helpNotePage.AddElement(helpNoteElement);
                }

                // Make the HTML element with 'help_note_opened' mapping ID an initially opened help note
                HtmlElementMapping helpNoteOpenedMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("help_note_opened");
                if (helpNoteOpenedMapping != null)
                {
                    PdfPage    helpNoteOpenedPage      = helpNoteOpenedMapping.PdfRectangles[0].PdfPage;
                    RectangleF helpNoteOpenedRectangle = helpNoteOpenedMapping.PdfRectangles[0].Rectangle;

                    // Create the text note
                    TextNoteElement helpNoteOpenedElement = new TextNoteElement(helpNoteOpenedRectangle, "This is an initially opened help note");
                    helpNoteOpenedElement.NoteIcon = TextNoteIcon.Help;
                    helpNoteOpenedElement.Open     = true;
                    helpNoteOpenedPage.AddElement(helpNoteOpenedElement);
                }

                // Make the HTML element with 'comment_note' mapping ID a comment note
                HtmlElementMapping commentNoteMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("comment_note");
                if (commentNoteMapping != null)
                {
                    PdfPage    commentNotePage      = commentNoteMapping.PdfRectangles[0].PdfPage;
                    RectangleF commentNoteRectangle = commentNoteMapping.PdfRectangles[0].Rectangle;

                    // Create the text note
                    TextNoteElement commentNoteElement = new TextNoteElement(commentNoteRectangle, "This is an initially closed comment note");
                    commentNoteElement.NoteIcon = TextNoteIcon.Comment;
                    commentNoteElement.Open     = false;
                    commentNotePage.AddElement(commentNoteElement);
                }

                // Make the HTML element with 'comment_note_opened' mapping ID an initially opened comment note
                HtmlElementMapping commentNoteOpenedMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("comment_note_opened");
                if (commentNoteOpenedMapping != null)
                {
                    PdfPage    commentNoteOpenedPage      = commentNoteOpenedMapping.PdfRectangles[0].PdfPage;
                    RectangleF commentNoteOpenedRectangle = commentNoteOpenedMapping.PdfRectangles[0].Rectangle;

                    // Create the text note
                    TextNoteElement commentNoteOpenedElement = new TextNoteElement(commentNoteOpenedRectangle, "This is an initially opened comment note");
                    commentNoteOpenedElement.NoteIcon = TextNoteIcon.Comment;
                    commentNoteOpenedElement.Open     = true;
                    commentNoteOpenedPage.AddElement(commentNoteOpenedElement);
                }

                // Make the HTML element with 'paragraph_note' mapping ID a paragraph note
                HtmlElementMapping paragraphNoteMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("paragraph_note");
                if (paragraphNoteMapping != null)
                {
                    PdfPage    paragraphNotePage      = paragraphNoteMapping.PdfRectangles[0].PdfPage;
                    RectangleF paragraphNoteRectangle = paragraphNoteMapping.PdfRectangles[0].Rectangle;

                    // Create the text note
                    TextNoteElement paragraphNoteElement = new TextNoteElement(paragraphNoteRectangle, "This is an initially closed paragraph note");
                    paragraphNoteElement.NoteIcon = TextNoteIcon.Paragraph;
                    paragraphNoteElement.Open     = false;
                    paragraphNotePage.AddElement(paragraphNoteElement);
                }

                // Make the HTML element with 'new_paragraph_note' mapping ID a new paragraph note
                HtmlElementMapping newParagraphNoteMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("new_paragraph_note");
                if (newParagraphNoteMapping != null)
                {
                    PdfPage    newParagraphNotePage      = newParagraphNoteMapping.PdfRectangles[0].PdfPage;
                    RectangleF newParagraphNoteRectangle = newParagraphNoteMapping.PdfRectangles[0].Rectangle;

                    // Create the text note
                    TextNoteElement newParagraphNoteElement = new TextNoteElement(newParagraphNoteRectangle, "This is an initially closed new paragraph note");
                    newParagraphNoteElement.NoteIcon = TextNoteIcon.NewParagraph;
                    newParagraphNoteElement.Open     = false;
                    newParagraphNotePage.AddElement(newParagraphNoteElement);
                }

                // Make the HTML element with 'key_note' mapping ID a key note
                HtmlElementMapping keyNoteMapping = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("key_note");
                if (keyNoteMapping != null)
                {
                    PdfPage    keyNotePage      = keyNoteMapping.PdfRectangles[0].PdfPage;
                    RectangleF keyNoteRectangle = keyNoteMapping.PdfRectangles[0].Rectangle;

                    // Create the text note
                    TextNoteElement keyNoteElement = new TextNoteElement(keyNoteRectangle, "This is an initially closed key note");
                    keyNoteElement.NoteIcon = TextNoteIcon.Key;
                    keyNoteElement.Open     = false;
                    keyNotePage.AddElement(keyNoteElement);
                }

                // Save the PDF document in a memory buffer
                byte[] outPdfBuffer = pdfDocument.Save();

                // Send the PDF file to browser
                FileResult fileResult = new FileContentResult(outPdfBuffer, "application/pdf");
                fileResult.FileDownloadName = "Text_Notes.pdf";

                return(fileResult);
            }
            finally
            {
                // Close the PDF document
                if (pdfDocument != null)
                {
                    pdfDocument.Close();
                }
            }
        }
Beispiel #10
0
        protected void convertToPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create a HTML to PDF converter object with default settings
            HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                htmlToPdfConverter.ServicePassword = textBoxServicePassword.Text;
            }

            // 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 = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed
            // Set this property to 0 if you don't need to wait for such asynchcronous operations to finish
            htmlToPdfConverter.ConversionDelay = 2;

            Document pdfDocument = null;

            // 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)
            {
                string htmlWithMappingAttributes = htmlStringTextBox.Text;
                string baseUrl = baseUrlTextBox.Text;

                // Convert a HTML string with mapping attributes to a PDF document object
                pdfDocument = htmlToPdfConverter.ConvertHtmlToPdfDocumentObject(htmlWithMappingAttributes, baseUrl);
            }
            else
            {
                string url = urlTextBox.Text;

                // Convert a HTML page with mapping attributes to a PDF document object
                pdfDocument = htmlToPdfConverter.ConvertUrlToPdfDocumentObject(url);
            }

            // Display detailed information about the selected elements
            StringBuilder htmlElementInfoBuilder = new StringBuilder();

            for (int mappingIndex = 0; mappingIndex < htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.Count; mappingIndex++)
            {
                HtmlElementMapping htmlElementInfo = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetByIndex(mappingIndex);

                // Get other information about HTML element
                string htmlElementTagName       = htmlElementInfo.HtmlElementTagName;
                string htmlElementID            = htmlElementInfo.HtmlElementId;
                string htmlElementMappingID     = htmlElementInfo.MappingId;
                string htmlElementCssClasssName = htmlElementInfo.HtmlElementCssClassName;
                string htmlElementHtmlCode      = htmlElementInfo.HtmlElementOuterHtml;
                string htmlElementInnerHtml     = htmlElementInfo.HtmlElementInnerHtml;
                string htmlElementText          = htmlElementInfo.HtmlElementText;
                NameValuePairsCollection htmlElementAttributes      = htmlElementInfo.HtmlElementAttributes;
                PdfRectangle[]           htmlElementRectanglesInPdf = 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 (int i = 0; i < htmlElementAttributes.Count; i++)
                {
                    NameValuePair nameValuePair = htmlElementAttributes.GetByIndex(i);
                    htmlElementInfoBuilder.AppendFormat("&nbsp;&nbsp;&nbsp;{0} = \"{1}\"<br/>", nameValuePair.Name, nameValuePair.Value);
                }


                htmlElementInfoBuilder.AppendFormat("<b>Location in PDF:</b><br/>");
                for (int i = 0; i < htmlElementRectanglesInPdf.Length; i++)
                {
                    PdfPage        pdfPage            = pdfDocument.GetPage(htmlElementRectanglesInPdf[i].PageIndex);
                    int            pdfPageIndex       = htmlElementRectanglesInPdf[i].PageIndex;
                    RectangleFloat rectangleInPdfPage = 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);
                }

                htmlElementInfoBuilder.AppendFormat("<br/>");
            }

            PdfPage        lastPdfPage       = pdfDocument.GetPage(htmlToPdfConverter.ConversionSummary.LastPageIndex);
            RectangleFloat lastPageRectangle = htmlToPdfConverter.ConversionSummary.LastPageRectangle;

            HtmlToPdfElement htmlElementInfoHtml = new HtmlToPdfElement(0, lastPageRectangle.Y + lastPageRectangle.Height + 1, htmlElementInfoBuilder.ToString(), null);

            lastPdfPage.AddElement(htmlElementInfoHtml);

            // Save the PDF document in a memory buffer
            byte[] outPdfBuffer = 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();
        }