Beispiel #1
0
        private void Body_OnCollision(Fixture fixtureA, Fixture fixtureB, VelcroPhysics.Collision.ContactSystem.Contact contact)
        {
            WorldComponent ground = (fixtureB.Body.UserData as WorldComponent);

            if (ground != null)
            {
                RectangleFloat bounds     = ground.Bounds;
                RectangleFloat heroBounds = Platman.Bounds;

                var bottom = Math.Abs(heroBounds.Bottom - bounds.Top);
                var top    = Math.Abs(heroBounds.Top - bounds.Bottom);
                var left   = Math.Abs(heroBounds.Left - bounds.Right);
                var right  = Math.Abs(heroBounds.Right - bounds.Left);

                float[] values = new float[] { bottom, top, left, right };

                Array.Sort(values);

                float edge = values[0];

                bool b = false;

                if (World.Gravity == VelocityValues.Instance.GravityDown)
                {
                    if (heroBounds.Bottom <= bounds.Top && bottom == edge)
                    {
                        b = true;
                    }
                }
                else if (World.Gravity == VelocityValues.Instance.GravityUp)
                {
                    if (heroBounds.Top > bounds.Bottom && top == edge)
                    {
                        b = true;
                    }
                }
                else if (World.Gravity == VelocityValues.Instance.GravityRight)
                {
                    if (heroBounds.Right <= bounds.Left && right == edge)
                    {
                        b = true;
                    }
                }
                else if (World.Gravity == VelocityValues.Instance.GravityLeft)
                {
                    if (heroBounds.Left > bounds.Right && left == edge)
                    {
                        b = true;
                    }
                }

                if (b)
                {
                    isOverGround = true;
                    overGround   = ground;
                    ApplyFallColisionImpulse();
                }
            }
        }
Beispiel #2
0
    public static RectangleFloat Create(float x_, float y_, float width_, float height_)
    {
        RectangleFloat r = new RectangleFloat();

        r.X      = x_;
        r.Y      = y_;
        r.Width  = width_;
        r.Height = height_;
        return(r);
    }
Beispiel #3
0
    //Divides CuboidNet() result by texture size, to get relative coordinates. (0-1, not 0-32 pixels).
    public static void CuboidNetNormalize(RectangleFloat[] coords, float texturewidth, float textureheight)
    {
        float AtiArtifactFix = 0.15f;

        for (int i = 0; i < 6; i++)
        {
            float x = ((coords[i].X + AtiArtifactFix) / texturewidth);
            float y = ((coords[i].Y + AtiArtifactFix) / textureheight);
            float w = ((coords[i].X + coords[i].Width - AtiArtifactFix) / texturewidth) - x;
            float h = ((coords[i].Y + coords[i].Height - AtiArtifactFix) / textureheight) - y;
            coords[i] = RectangleFloat.Create(x, y, w, h);
        }
    }
Beispiel #4
0
 //Maps description of position of 6 faces
 //of a single cuboid in texture file to UV coordinates (in pixels)
 //(one RectangleF in texture file for each 3d face of cuboid).
 //Arguments:
 // Size (in pixels) in 2d cuboid net.
 // Start position of 2d cuboid net in texture file.
 public static RectangleFloat[] CuboidNet(float tsizex, float tsizey, float tsizez, float tstartx, float tstarty)
 {
     RectangleFloat[] coords = new RectangleFloat[6];
     {
         coords[0] = RectangleFloat.Create(tsizez + tstartx, tsizez + tstarty, tsizex, tsizey);              //front
         coords[1] = RectangleFloat.Create(2 * tsizez + tsizex + tstartx, tsizez + tstarty, tsizex, tsizey); //back
         coords[2] = RectangleFloat.Create(tstartx, tsizez + tstarty, tsizez, tsizey);                       //right
         coords[3] = RectangleFloat.Create(tsizez + tsizex + tstartx, tsizez + tstarty, tsizez, tsizey);     //left
         coords[4] = RectangleFloat.Create(tsizez + tstartx, tstarty, tsizex, tsizez);                       //top
         coords[5] = RectangleFloat.Create(tsizez + tsizex + tstartx, tstarty, tsizex, tsizez);              //bottom
     }
     return(coords);
 }
        protected void createPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create a PDF document
            Document pdfDocument = new Document(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                pdfDocument.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
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Add a page to PDF document
            PdfPage pdfPage = pdfDocument.AddPage();

            // The font used for titles in PDF document
            PdfFont titlesFont = new PdfFont("Times New Roman", 10, true);

            titlesFont.Bold = true;
            // The font used for field names in PDF document
            PdfFont fieldNameFont = new PdfFont("Times New Roman", 10, true);
            // The font used for buttons text in PDF document
            PdfFont buttonTextFont = new PdfFont("Times New Roman", 10, false);
            // The font used for PDF form text box fields
            PdfFont textFieldFont = new PdfFont(StdFontBaseFamily.Helvetica, 8);
            // The font used for PDF form combo box fields
            PdfFont comboBoxFieldFont = new PdfFont(StdFontBaseFamily.Helvetica, 8);

            // Add document title
            TextElement titleTextElement = new TextElement(5, 5, "Create PDF Forms", titlesFont);

            pdfPage.AddElement(titleTextElement);

            // Add a text box field to PDF form
            TextElement fieldNameTextElement = new TextElement(5, 30, 60, "First name:", fieldNameFont);

            pdfPage.AddElement(fieldNameTextElement);
            RectangleFloat fieldBoundingRectangle = new RectangleFloat(0, 50, 150, 15);
            // Create the form field
            PdfFormTextBox firstNameTextBoxField = new PdfFormTextBox(fieldBoundingRectangle, "Enter First Name", textFieldFont);

            pdfDocument.AddFormField(firstNameTextBoxField, 10, true, false, 0, true, false);
            // Set unique form field name used when the form is submitted
            firstNameTextBoxField.Name = "firstName";
            // Set the form field default value
            firstNameTextBoxField.DefaultValue = "A default first name";
            // Set form field style
            firstNameTextBoxField.Style.BackColor = RgbColor.AliceBlue;

            // Add a text box field to PDF form
            fieldNameTextElement = new TextElement(0, 75, 60, "Last name:", fieldNameFont);
            pdfDocument.AddElement(fieldNameTextElement, 5, false, 10, true);
            fieldBoundingRectangle = new RectangleFloat(0, 90, 150, 15);
            // Create the form field
            PdfFormTextBox textBoxField = new PdfFormTextBox(fieldBoundingRectangle, "Enter Last Name", textFieldFont);

            pdfDocument.AddFormField(textBoxField, 10, true, false, 0, true, false);
            // Set unique form field name used when the form is submitted
            textBoxField.Name = "lastName";
            // Set the form field default value
            textBoxField.DefaultValue = "A default last name";
            // Set form field style
            textBoxField.Style.BackColor = RgbColor.MistyRose;

            // Add a password text box field to PDF form
            fieldNameTextElement = new TextElement(0, 105, 60, "Password:"******"", textFieldFont);

            pdfDocument.AddFormField(passwordTextBoxField, 10, true, false, 0, true, false);
            // Set unique form field name used when the form is submitted
            passwordTextBoxField.Name = "password";
            // Set form field style
            passwordTextBoxField.Style.BackColor = RgbColor.AliceBlue;
            // Set the password mode for the text box
            passwordTextBoxField.IsPassword = true;

            // Add a radio buttons group to PDF form
            fieldNameTextElement = new TextElement(0, 0, 60, "Gender:", fieldNameFont);
            pdfDocument.AddElement(fieldNameTextElement, 5, false, 10, true);

            // Create the radio buttons group
            PdfFormRadioButtonsGroup radioButtonsGroup = new PdfFormRadioButtonsGroup();

            pdfDocument.AddFormField(radioButtonsGroup);
            // Set unique form field name used when the form is submitted
            radioButtonsGroup.Name = "gender";
            // Set style of the radio buttons in this group
            radioButtonsGroup.Style.BackColor = RgbColor.AntiqueWhite;

            // Add the first radio button to group
            RectangleFloat radioButtonRectangle = new RectangleFloat(0, 0, 50, 10);
            // Create the form field
            PdfFormRadioButton radioButtonFieldMale = new PdfFormRadioButton(radioButtonRectangle, "male");

            radioButtonsGroup.AddRadioButton(radioButtonFieldMale, 10, true, false, 0, true, false);

            fieldNameTextElement = new TextElement(0, 0, 30, "Male", fieldNameFont);
            pdfDocument.AddElement(fieldNameTextElement, 5, true, false, 0, true, false);

            // Add the second radio button to group
            radioButtonRectangle = new RectangleFloat(0, 0, 50, 10);
            // Create the form field
            PdfFormRadioButton radioButtonFieldFemale = new PdfFormRadioButton(radioButtonRectangle, "female");

            radioButtonsGroup.AddRadioButton(radioButtonFieldFemale, 15, true, false, 0, true, false);

            fieldNameTextElement = new TextElement(0, 0, 30, "Female", fieldNameFont);
            pdfDocument.AddElement(fieldNameTextElement, 5, true, false, 0, true, false);

            // Set the selected radio btton in group
            radioButtonsGroup.SetCheckedRadioButton(radioButtonFieldFemale);

            // Add a checkbox field to PDF form
            fieldNameTextElement = new TextElement(0, 0, 60, "Vehicle:", fieldNameFont);
            pdfDocument.AddElement(fieldNameTextElement, 5, false, 10, true);
            fieldBoundingRectangle = new RectangleFloat(0, 0, 10, 10);
            // Create the form field
            PdfFormCheckBox checkBoxField = new PdfFormCheckBox(fieldBoundingRectangle, true);

            pdfDocument.AddFormField(checkBoxField, 10, true, false, 0, true, false);
            // Set unique form field name used when the form is submitted
            checkBoxField.Name = "haveCar";
            // Set form field style
            checkBoxField.Style.BackColor = RgbColor.AntiqueWhite;
            // Set checkbox field checked state
            checkBoxField.Checked = true;

            fieldNameTextElement = new TextElement(0, 0, 50, "I have a car", fieldNameFont);
            pdfDocument.AddElement(fieldNameTextElement, 10, true, false, 0, true, false);

            // Add a combo box list field to PDF form
            fieldNameTextElement = new TextElement(0, 0, 60, "Vehicle Type:", fieldNameFont);
            pdfDocument.AddElement(fieldNameTextElement, 5, false, 10, true);

            fieldBoundingRectangle = new RectangleFloat(0, 0, 50, 15);
            string[] comboBoxItems = new string[] { "Volvo", "Saab", "Audi", "Opel" };
            // Create the form field
            PdfFormComboBox comboBoxField = new PdfFormComboBox(fieldBoundingRectangle, comboBoxItems, comboBoxFieldFont);

            pdfDocument.AddFormField(comboBoxField, 10, true, false, 0, true, false);
            // Set unique form field name used when the form is submitted
            comboBoxField.Name = "vehicleType";
            // Set the form field default value
            comboBoxField.DefaultValue = "Audi";
            // Set form field style
            comboBoxField.Style.BackColor = RgbColor.LightCyan;
            // Set selected item in combo box
            comboBoxField.Value = "Audi";

            // Add a multiline text box field to PDF form
            fieldNameTextElement = new TextElement(0, 0, 60, "Comments:", fieldNameFont);
            pdfDocument.AddElement(fieldNameTextElement, 5, false, 10, true);

            fieldBoundingRectangle = new RectangleFloat(0, 0, 150, 60);
            // Create the form field
            PdfFormTextBox multilineTextBoxField = new PdfFormTextBox(fieldBoundingRectangle,
                                                                      "Enter your comments here:\r\nFirst comment line\r\nSecond comment line", textFieldFont);

            pdfDocument.AddFormField(multilineTextBoxField, 10, true, false, 0, true, false);
            // Set unique form field name used when the form is submitted
            multilineTextBoxField.Name = "comments";
            // Set form field style
            multilineTextBoxField.Style.BackColor = RgbColor.AliceBlue;
            // Set the multiline mode for text box field
            multilineTextBoxField.IsMultiLine = true;

            // Add a form submit button to PDF form
            fieldBoundingRectangle = new RectangleFloat(0, 0, 75, 15);
            PdfFormButton submitFormButton = new PdfFormButton(fieldBoundingRectangle, "Submit", buttonTextFont);

            pdfDocument.AddFormField(submitFormButton, 5, false, 10, true);
            // Set unique form field name used when the form is submitted
            submitFormButton.Name = "submitFormButton";
            // Set form field style
            submitFormButton.Style.BackColor = RgbColor.Beige;
            // Create the form submit action
            PdfSubmitFormAction submitFormAction = new PdfSubmitFormAction(submitUrlTextBox.Text);

            submitFormAction.Flags |= PdfFormSubmitFlags.ExportFormat;
            if (getMethodRadioButton.Checked)
            {
                submitFormAction.Flags |= PdfFormSubmitFlags.GetMethod;
            }
            // Set the form submit button action
            submitFormButton.Action = submitFormAction;

            // Add a form reset button to PDF form
            fieldBoundingRectangle = new RectangleFloat(0, 0, 75, 15);
            PdfFormButton resetFormButton = new PdfFormButton(fieldBoundingRectangle, "Reset", buttonTextFont);

            pdfDocument.AddFormField(resetFormButton, 10, true, false, 0, true, false);
            // Set unique form field name used when the form is submitted
            resetFormButton.Name = "resetFormButton";
            // Set form field style
            resetFormButton.Style.BackColor = RgbColor.Beige;
            // Create the form reset action
            PdfResetFormAction resetFormAction = new PdfResetFormAction();

            // Set the form reset button action
            resetFormButton.Action = resetFormAction;

            // 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=Create_PDF_Forms.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 #6
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 htmlWithDigitalSignatureMarker = htmlStringTextBox.Text;
            string baseUrl = baseUrlTextBox.Text;

            // Convert a HTML string with a marker for digital signature to a PDF document object
            Document 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      = pdfDocument.GetPage(digitalSignatureMapping.PdfRectangles[0].PageIndex);
                RectangleFloat digitalSignatureRectangle = digitalSignatureMapping.PdfRectangles[0].Rectangle;

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

                // Create the digital signature
                DigitalSignatureElement signature = new DigitalSignatureElement(digitalSignatureRectangle, certificateFilePath, "evopdf", 0);
                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();
        }
        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;

            // Select the HTML elements for which to retrieve location and other information from HTML document
            htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementSelectors = new string[] { htmlElementsSelectorTextBox.Text };

            // Convert HTML page to a PDF document object which can be further modified to highlight the selected elements
            Document pdfDocument = htmlToPdfConverter.ConvertUrlToPdfDocumentObject(urlTextBox.Text);

            // Highlight the selected elements in PDF with colored rectangles
            for (int i = 0; i < htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.Count; i++)
            {
                HtmlElementMapping htmlElementInfo = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetByIndex(i);
                // Get other information about HTML element
                string htmlElementTagName = htmlElementInfo.HtmlElementTagName;
                string htmlElementID      = htmlElementInfo.HtmlElementId;

                // Hightlight the HTML element in PDF

                // A HTML element can span over many PDF pages and therefore the mapping of the HTML element in PDF document consists
                // in a list of rectangles, one rectangle for each PDF page where this element was rendered
                foreach (PdfRectangle htmlElementLocationInPdf in htmlElementInfo.PdfRectangles)
                {
                    // Get the HTML element location in PDF page
                    PdfPage        htmlElementPdfPage            = pdfDocument.GetPage(htmlElementLocationInPdf.PageIndex);
                    RectangleFloat htmlElementRectangleInPdfPage = htmlElementLocationInPdf.Rectangle;

                    // Highlight the HTML element element with a colored rectangle in PDF
                    RectangleElement highlightRectangle = new RectangleElement(htmlElementRectangleInPdfPage.X, htmlElementRectangleInPdfPage.Y,
                                                                               htmlElementRectangleInPdfPage.Width, htmlElementRectangleInPdfPage.Height);

                    if (htmlElementTagName.ToLower() == "h1")
                    {
                        highlightRectangle.ForeColor = RgbColor.Blue;
                    }
                    else if (htmlElementTagName.ToLower() == "h2")
                    {
                        highlightRectangle.ForeColor = RgbColor.Green;
                    }
                    else if (htmlElementTagName.ToLower() == "h3")
                    {
                        highlightRectangle.ForeColor = RgbColor.Red;
                    }
                    else if (htmlElementTagName.ToLower() == "h4")
                    {
                        highlightRectangle.ForeColor = RgbColor.Yellow;
                    }
                    else if (htmlElementTagName.ToLower() == "h5")
                    {
                        highlightRectangle.ForeColor = RgbColor.Indigo;
                    }
                    else if (htmlElementTagName.ToLower() == "h6")
                    {
                        highlightRectangle.ForeColor = RgbColor.Orange;
                    }
                    else
                    {
                        highlightRectangle.ForeColor = RgbColor.Navy;
                    }

                    highlightRectangle.LineStyle.LineDashStyle = LineDashStyle.Solid;

                    htmlElementPdfPage.AddElement(highlightRectangle);
                }
            }

            // 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_API_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();
        }
Beispiel #8
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();
        }
 public static RectangleFloat Create(float x_, float y_, float width_, float height_)
 {
     RectangleFloat r = new RectangleFloat();
     r.X = x_;
     r.Y = y_;
     r.Width = width_;
     r.Height = height_;
     return r;
 }
    public static void DrawCuboid2(Game game, float posX, float posY, float posZ,
        float sizeX, float sizeY, float sizeZ,
        RectangleFloat[] texturecoords, float light)
    {
        ModelData data = new ModelData();
        data.xyz = new float[4 * 6 * 3];
        data.uv = new float[4 * 6 * 2];
        data.rgba = new byte[4 * 6 * 4];
        int light255 = game.platform.FloatToInt(light * 255);
        int color = Game.ColorFromArgb(255, light255, light255, light255);

        RectangleFloat rect;

        //right
        rect = texturecoords[2];
        AddVertex(data, posX, posY, posZ, rect.X, rect.Bottom(), color);
        AddVertex(data, posX, posY, posZ + sizeZ, rect.X + rect.Width, rect.Bottom(), color);
        AddVertex(data, posX, posY + sizeY, posZ + sizeZ, rect.X + rect.Width, rect.Y, color);
        AddVertex(data, posX, posY + sizeY, posZ, rect.X, rect.Y, color);

        //left
        rect = texturecoords[3];
        AddVertex(data, posX + sizeX, posY, posZ + sizeZ, rect.X, rect.Bottom(), color);
        AddVertex(data, posX + sizeX, posY, posZ, rect.X + rect.Width, rect.Bottom(), color);
        AddVertex(data, posX + sizeX, posY + sizeY, posZ, rect.X + rect.Width, rect.Y, color);
        AddVertex(data, posX + sizeX, posY + sizeY, posZ + sizeZ, rect.X, rect.Y, color);

        //back
        rect = texturecoords[1];
        AddVertex(data, posX + sizeX, posY, posZ, rect.X, rect.Bottom(), color);
        AddVertex(data, posX, posY, posZ, rect.X + rect.Width, rect.Bottom(), color);
        AddVertex(data, posX, posY + sizeY, posZ, rect.X + rect.Width, rect.Y, color);
        AddVertex(data, posX + sizeX, posY + sizeY, posZ, rect.X, rect.Y, color);

        //front
        rect = texturecoords[0];
        AddVertex(data, posX + sizeX, posY, posZ + sizeZ, rect.X + rect.Width, rect.Bottom(), color);
        AddVertex(data, posX, posY, posZ + sizeZ, rect.X, rect.Bottom(), color);
        AddVertex(data, posX, posY + sizeY, posZ + sizeZ, rect.X, rect.Y, color);
        AddVertex(data, posX + sizeX, posY + sizeY, posZ + sizeZ, rect.X + rect.Width, rect.Y, color);

        //top
        rect = texturecoords[4];
        AddVertex(data, posX, posY + sizeY, posZ, rect.X, rect.Y, color);
        AddVertex(data, posX, posY + sizeY, posZ + sizeZ, rect.X, rect.Bottom(), color);
        AddVertex(data, posX + sizeX, posY + sizeY, posZ + sizeZ, rect.X + rect.Width, rect.Bottom(), color);
        AddVertex(data, posX + sizeX, posY + sizeY, posZ, rect.X + rect.Width, rect.Y, color);

        //bottom
        rect = texturecoords[5];
        AddVertex(data, posX, posY, posZ, rect.X, rect.Y, color);
        AddVertex(data, posX, posY, posZ + sizeZ, rect.X, rect.Bottom(), color);
        AddVertex(data, posX + sizeX, posY, posZ + sizeZ, rect.X + rect.Width, rect.Bottom(), color);
        AddVertex(data, posX + sizeX, posY, posZ, rect.X + rect.Width, rect.Y, color);

        data.indices = new int[6 * 6];
        for (int i = 0; i < 6; i++)
        {
            data.indices[i * 6 + 0] = i * 4 + 3;
            data.indices[i * 6 + 1] = i * 4 + 2;
            data.indices[i * 6 + 2] = i * 4 + 0;
            data.indices[i * 6 + 3] = i * 4 + 2;
            data.indices[i * 6 + 4] = i * 4 + 1;
            data.indices[i * 6 + 5] = i * 4 + 0;
        }
        data.indicesCount = 36;

        game.platform.GlDisableCullFace();
        game.DrawModelData(data);
        game.platform.GlEnableCullFace();
    }
 //Divides CuboidNet() result by texture size, to get relative coordinates. (0-1, not 0-32 pixels).
 public static void CuboidNetNormalize(RectangleFloat[] coords, float texturewidth, float textureheight)
 {
     float AtiArtifactFix = 0.15f;
     for (int i = 0; i < 6; i++)
     {
         float x = ((coords[i].X + AtiArtifactFix) / texturewidth);
         float y = ((coords[i].Y + AtiArtifactFix) / textureheight);
         float w = ((coords[i].X + coords[i].Width - AtiArtifactFix) / texturewidth) - x;
         float h = ((coords[i].Y + coords[i].Height - AtiArtifactFix) / textureheight) - y;
         coords[i] = RectangleFloat.Create(x, y, w, h);
     }
 }
 //Maps description of position of 6 faces
 //of a single cuboid in texture file to UV coordinates (in pixels)
 //(one RectangleF in texture file for each 3d face of cuboid).
 //Arguments:
 // Size (in pixels) in 2d cuboid net.
 // Start position of 2d cuboid net in texture file.
 public static RectangleFloat[] CuboidNet(float tsizex, float tsizey, float tsizez, float tstartx, float tstarty)
 {
     RectangleFloat[] coords = new RectangleFloat[6];
     {
         coords[0] = RectangleFloat.Create(tsizez + tstartx, tsizez + tstarty, tsizex, tsizey);//front
         coords[1] = RectangleFloat.Create(2 * tsizez + tsizex + tstartx, tsizez + tstarty, tsizex, tsizey);//back
         coords[2] = RectangleFloat.Create(tstartx, tsizez + tstarty, tsizez, tsizey);//right
         coords[3] = RectangleFloat.Create(tsizez + tsizex + tstartx, tsizez + tstarty, tsizez, tsizey);//left
         coords[4] = RectangleFloat.Create(tsizez + tstartx, tstarty, tsizex, tsizez);//top
         coords[5] = RectangleFloat.Create(tsizez + tsizex + tstartx, tstarty, tsizex, tsizez);//bottom
     }
     return coords;
 }
    void DrawNode(string parent, float headDeg, float light)
    {
        for (int i = 0; i < m.nodesCount; i++)
        {
            Node n = m.nodes[i];
            if (n == null)
            {
                continue;
            }
            if (n.parentName != parent)
            {
                continue;
            }
            game.GLPushMatrix();
            RectangleFloat[] r = new RectangleFloat[6];
            r = CuboidRenderer.CuboidNet(n.sizex, n.sizey, n.sizez, n.u, n.v);
            CuboidRenderer.CuboidNetNormalize(r, m.global.texw, m.global.texh);
            GetAnimation(n, tempVec3, KeyframeType.Scale);
            if (tempVec3[0] != 0 && tempVec3[1] != 0 && tempVec3[2] != 0)
            {
                game.GLScale(tempVec3[0], tempVec3[1], tempVec3[2]);
            }
            GetAnimation(n, tempVec3, KeyframeType.Position);
            tempVec3[0] /= 16;
            tempVec3[1] /= 16;
            tempVec3[2] /= 16;
            if (!IsZero(tempVec3))
            {
                game.GLTranslate(tempVec3[0], tempVec3[1], tempVec3[2]);
            }
            GetAnimation(n, tempVec3, KeyframeType.Rotation);
            if (tempVec3[0] != 0)
            {
                game.GLRotate(tempVec3[0], 1, 0, 0);
            }
            if (tempVec3[1] != 0)
            {
                game.GLRotate(tempVec3[1], 0, 1, 0);
            }
            if (tempVec3[2] != 0)
            {
                game.GLRotate(tempVec3[2], 0, 0, 1);
            }
            if (n.head == 1)
            {
                game.GLRotate(headDeg, 1, 0, 0);
            }
            GetAnimation(n, tempVec3, KeyframeType.Pivot);
            tempVec3[0] /= 16;
            tempVec3[1] /= 16;
            tempVec3[2] /= 16;
            game.GLTranslate(tempVec3[0], tempVec3[1], tempVec3[2]);
            GetAnimation(n, tempVec3, KeyframeType.Size);
            tempVec3[0] /= 16;
            tempVec3[1] /= 16;
            tempVec3[2] /= 16;

            // Use binary minus because unary minus is truncated to integer in cito
            CuboidRenderer.DrawCuboid2(game, 0 - tempVec3[0] / 2, 0 - tempVec3[1] / 2, 0 - tempVec3[2] / 2, tempVec3[0], tempVec3[1], tempVec3[2], r, light);

            DrawNode(n.name, headDeg, light);
            game.GLPopMatrix();
        }
    }
        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;

            // Select all images from HTML page
            htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementSelectors = new string[] { "img" };

            // Exclude the original images from rendering becuase they will be replaced by an image from local file system
            htmlToPdfConverter.HiddenHtmlElementsSelectors = new string[] { "img" };

            // Convert a HTML string with images to replace to a PDF document object
            Document pdfDocument = htmlToPdfConverter.ConvertUrlToPdfDocumentObject(urlTextBox.Text);

            // Replace the images selected in HTML using special attributes with images from local file system
            int mappingsCount = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.Count;

            for (int i = 0; i < mappingsCount; i++)
            {
                HtmlElementMapping imageElementInfo = htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetByIndex(i);
                PdfPage            imagePdfPage     = pdfDocument.GetPage(imageElementInfo.PdfRectangles[0].PageIndex);
                RectangleFloat     imageRectangle   = imageElementInfo.PdfRectangles[0].Rectangle;

                ImageElement newImageElement = new ImageElement(imageRectangle.X, imageRectangle.Y, imageRectangle.Width, imageRectangle.Height,
                                                                Server.MapPath("~/DemoAppFiles/Input/Images/box.jpg"));
                newImageElement.EnlargeEnabled = true;
                imagePdfPage.AddElement(newImageElement);
            }

            // 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=Replace_with_Higher_Quality_Images.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 #15
0
        protected void createPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create a PDF document
            Document pdfDocument = new Document(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                pdfDocument.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
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

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

            // Add a page to PDF document
            PdfPage pdfPage = pdfDocument.AddPage();

            // The titles font used to mark various sections of the PDF document
            PdfFont titleFont = new PdfFont("Times New Roman", 10, true);

            titleFont.Bold = true;
            PdfFont subtitleFont = new PdfFont("Times New Roman", 8, true);

            // Add document title
            TextElement titleTextElement = new TextElement(5, 5, "Attach Files and Streams to a PDF Document", titleFont);

            pdfPage.AddElement(titleTextElement);

            // 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");

            // Add the text element
            string      text        = "Click the next icon to open the attachment from a file:";
            TextElement textElement = new TextElement(0, 0, 200, text, subtitleFont);

            pdfDocument.AddElement(textElement, 15);

            // Create an attachment from file with paperclip icon in PDF
            string fileAttachmentWithIconPath = Server.MapPath("~/DemoAppFiles/Input/Attach_Files/Attachment_File_Icon.txt");
            // Create the attachment from file
            RectangleFloat        attachFromFileIconRectangle = new RectangleFloat(0, 0, 6, 10);
            FileAttachmentElement attachFromFileElement       = new FileAttachmentElement(attachFromFileIconRectangle, fileAttachmentWithIconPath);

            attachFromFileElement.IconType  = FileAttachmentIcon.Paperclip;
            attachFromFileElement.Text      = "Attachment from File with Paperclip Icon";
            attachFromFileElement.IconColor = RgbColor.Blue;
            pdfDocument.AddElement(attachFromFileElement, 10, true, false, 0, true, false);

            // Add the text element
            text        = "Click the next icon to open the attachment from a stream:";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            // Create an attachment from stream with pushpin icon in PDF
            string fileStreamAttachmentWithIconPath = Server.MapPath("~/DemoAppFiles/Input/Attach_Files/Attachment_Stream_Icon.txt");

            byte[] attachmentDataWithIcon = System.IO.File.ReadAllBytes(fileStreamAttachmentWithIconPath);
            // Create the attachment from stream
            RectangleFloat        attachFromStreamIconRectangle = new RectangleFloat(0, 0, 6, 10);
            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;
            pdfDocument.AddElement(attachFromStreamElement, 10, true, false, 0, true, false);

            // 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_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 #16
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();
        }
Beispiel #17
0
        static int Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Title           = "Playgound Pro C# .Net Core API";
            string[] theArgs = Environment.GetCommandLineArgs();
            foreach (string arg in theArgs)
            {
                Console.WriteLine("Arg: {0}", arg);
            }

            ShowEnvironmentDetails();
            ShowNumberFormat();
            ShowDefaultDeclarations();
            TryFromStringWithTryParse();
            Playground playground = new Playground();

            playground.LinqQueryOverInts();
            playground.JaggedMultiDimensionalArrays();

            playground.CalculateAverage(out double average, 4.0, 3.0, 5.0);

            Console.WriteLine(@"Average {0}", average);

            Playground.Days currDay = Playground.Days.Monday;
            playground.GreetOnDay(currDay);

            Rectangle <int> newRect = new Rectangle <int>(@"Original Rectangle Info", 1, 2);

            Console.WriteLine(@"Original Rect Message");
            newRect.Message();
            Rectangle <int> copyRect = newRect;

            copyRect.rectInfo.InfoString = @"Modified Rectangle Info";
            Console.WriteLine(@"Copy Rect Message");
            copyRect.Message();
            Console.WriteLine(@"Original Rect Message post modification");
            newRect.Message();

            Console.WriteLine(@"Tuple members");
            Tuples tuples = new Tuples();

            tuples.PlayWithTuples();

            Console.WriteLine(@"Split Members");
            Tuples splitNames = new Tuples();

            var(first, _, last) = splitNames.SplitNames("Vaibhav Ramesh Panchal");
            Console.WriteLine($"{first} {last}");

            Point <double> deconstructedTuple = new Point <double>(30.0f, 40.0f);

            var(xPos, yPos, color) = deconstructedTuple.Deconstruct();
            Console.WriteLine($"xPos : {xPos}, yPos : {yPos}, color : {color}");


            // Exception DemoInteface
            try
            {
                HarleyDavidson harleyDavidson = new HarleyDavidson("harley", 1, "HR1001");
                for (int i = 0; i < 5000; i++)
                {
                    harleyDavidson.SpeedUpBy(i);
                }
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("===Speed Exception===");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.TargetSite);
                Console.WriteLine(e.StackTrace);
                Console.WriteLine("===Speed Exception===");
                Console.ForegroundColor = ConsoleColor.White;
            }


            // Interface
            //ShapesDemo.DemoInteface();
            ShapesDemo.DemoExplicitInterface();

            //EnumDemo.Demo();
            //EnumDemo.DemoCustomerEnumerator();
            EnumDemo.DemoYield();
            EmployeeDemo.DemoSortedSet();

            Calculator <int> .CalculatorDemo();

            CarDemo carDemo = new CarDemo();

            carDemo.DemoEvents();


            NumberDemo.LamdaDemo();

            PersonCollection.PersonCollectionDemo();

            RectangleFloat.CastDemo();
            Console.ReadKey();



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

            // Create a PDF document
            Document pdfDocument = new Document(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                pdfDocument.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
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Add a page to PDF document
            PdfPage pdfPage = pdfDocument.AddPage();

            // The titles font used to mark various sections of the PDF document
            PdfFont titleFont = new PdfFont("Times New Roman", 10, true);

            titleFont.Bold = true;
            PdfFont subtitleFont = new PdfFont("Times New Roman", 8, true);

            // The links text font
            PdfFont linkTextFont = new PdfFont("Times New Roman", 8, true);

            linkTextFont.Bold      = true;
            linkTextFont.Underline = true;

            // Add document title
            TextElement titleTextElement = new TextElement(5, 5, "Create URI Links in PDF Document", titleFont);

            pdfPage.AddElement(titleTextElement);

            // Make a text in PDF a link to a web page

            // Add the text element
            string      text            = "Click this text to open a web page!";
            TextElement linkTextElement = new TextElement(0, 0, 150, text, linkTextFont);

            linkTextElement.ForeColor = RgbColor.Navy;
            pdfDocument.AddElement(linkTextElement, 15);

            // Create the URI link element having the size of the text element
            RectangleFloat linkRectangle = RectangleFloat.Empty;
            string         url           = "http://www.evopdf.com";
            LinkUrlElement uriLink       = new LinkUrlElement(linkRectangle, url);

            // Add the URI link to PDF document
            pdfDocument.AddElement(uriLink, 0, true, true, 0, true, false);

            // Make an image in PDF a link to a web page

            TextElement subtitleTextElement = new TextElement(0, 0, "Click the image below to open a web page:", subtitleFont);

            pdfDocument.AddElement(subtitleTextElement, 10);

            // Add the image element
            ImageElement linkImageElement = new ImageElement(0, 0, 120, Server.MapPath("~/DemoAppFiles/Input/Images/logo.jpg"));

            pdfDocument.AddElement(linkImageElement);

            // Create the URI link element having the size of the image element
            linkRectangle = RectangleFloat.Empty;
            uriLink       = new LinkUrlElement(linkRectangle, url);

            // Add the URI link to PDF document
            pdfDocument.AddElement(uriLink, 0, true, true, 0, true, false);

            // 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=URI_Links.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 #19
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 PDF document
            Document pdfDocument = new Document(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                pdfDocument.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
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Add a page to PDF document
            PdfPage pdfPage = pdfDocument.AddPage();

            // The titles font used to mark various sections of the PDF document
            PdfFont titleFont = new PdfFont("Times New Roman", 8, true);

            TextElement titleTextElement = new TextElement(5, 5, "Execute an Acrobat JavaScript code when the button below is clicked. Using a JavaScript code you can open the print dialog, display an alert message or set the document zoom level in PDF viewer.", titleFont);

            pdfPage.AddElement(titleTextElement);

            PdfPage        buttonPdfPage   = pdfDocument.GetPage(0);
            RectangleFloat buttonRectangle = new RectangleFloat(5, 40, 100, 20);

            // 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();
        }
Beispiel #20
0
        protected void createPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create a PDF document
            Document pdfDocument = new Document(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                pdfDocument.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
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Add a page to PDF document
            PdfPage pdfPage = pdfDocument.AddPage();

            // The titles font used to mark various sections of the PDF document
            PdfFont titleFont = new PdfFont("Times New Roman", 10, true);

            titleFont.Bold = true;
            PdfFont subtitleFont = new PdfFont("Times New Roman", 8, true);

            // Add document title
            TextElement titleTextElement = new TextElement(5, 5, "Add Text Notes to a PDF Document", titleFont);

            pdfPage.AddElement(titleTextElement);

            // Add the text element
            string      text        = "Click the next icon to open the the text note:";
            TextElement textElement = new TextElement(0, 0, 200, text, subtitleFont);

            pdfDocument.AddElement(textElement, 10);

            RectangleFloat textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement textNoteElement = new TextNoteElement(textNoteRectangle, "This is an initially closed text note");

            textNoteElement.NoteIcon = TextNoteIcon.Note;
            textNoteElement.Open     = false;
            pdfDocument.AddElement(textNoteElement, 10, true, false, 0, true, false);

            // Add the text element
            text        = "This is an already opened text note:";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement textNoteOpenedElement = new TextNoteElement(textNoteRectangle, "This is an initially opened text note");

            textNoteOpenedElement.NoteIcon = TextNoteIcon.Note;
            textNoteOpenedElement.Open     = true;
            pdfDocument.AddElement(textNoteOpenedElement, 10, true, false, 0, true, false);


            // Add the text element
            text        = "Click the next icon to open the the help note:";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement helpNoteElement = new TextNoteElement(textNoteRectangle, "This is an initially closed help note");

            helpNoteElement.NoteIcon = TextNoteIcon.Help;
            helpNoteElement.Open     = false;
            pdfDocument.AddElement(helpNoteElement, 10, true, false, 0, true, false);

            // Add the text element
            text        = "This is an already opened help note:";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement helpNoteOpenedElement = new TextNoteElement(textNoteRectangle, "This is an initially opened help note");

            helpNoteOpenedElement.NoteIcon = TextNoteIcon.Help;
            helpNoteOpenedElement.Open     = true;
            pdfDocument.AddElement(helpNoteOpenedElement, 10, true, false, 0, true, false);

            // Add the text element
            text        = "Click the next icon to open the comment:";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement commentNoteElement = new TextNoteElement(textNoteRectangle, "This is an initially closed comment note");

            commentNoteElement.NoteIcon = TextNoteIcon.Comment;
            commentNoteElement.Open     = false;
            pdfDocument.AddElement(commentNoteElement, 10, true, false, 0, true, false);


            // Add the text element
            text        = "This is an already opened comment:";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement commentNoteOpenedElement = new TextNoteElement(textNoteRectangle, "This is an initially opened comment note");

            commentNoteOpenedElement.NoteIcon = TextNoteIcon.Comment;
            commentNoteOpenedElement.Open     = true;
            pdfDocument.AddElement(commentNoteOpenedElement, 10, true, false, 0, true, false);

            // Add the text element
            text        = "Click the next icon to open the paragraph note: ";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement paragraphNoteElement = new TextNoteElement(textNoteRectangle, "This is an initially closed paragraph note");

            paragraphNoteElement.NoteIcon = TextNoteIcon.Paragraph;
            paragraphNoteElement.Open     = false;
            pdfDocument.AddElement(paragraphNoteElement, 10, true, false, 0, true, false);

            // Add the text element
            text        = "Click the next icon to open the new paragraph note:";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement newParagraphNoteElement = new TextNoteElement(textNoteRectangle, "This is an initially closed new paragraph note");

            newParagraphNoteElement.NoteIcon = TextNoteIcon.NewParagraph;
            newParagraphNoteElement.Open     = false;
            pdfDocument.AddElement(newParagraphNoteElement, 10, true, false, 0, true, false);

            // Add the text element
            text        = "Click the next icon to open the key note:";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement keyNoteElement = new TextNoteElement(textNoteRectangle, "This is an initially closed key note");

            keyNoteElement.NoteIcon = TextNoteIcon.Key;
            keyNoteElement.Open     = false;
            pdfDocument.AddElement(keyNoteElement, 10, true, false, 0, true, false);

            // 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 #21
0
    void DrawNode(string parent, float headDeg, float light)
    {
        for (int i = 0; i < m.nodesCount; i++)
        {
            Node n = m.nodes[i];
            if (n == null)
            {
                continue;
            }
            if (n.parentName != parent)
            {
                continue;
            }
            game.GLPushMatrix();
            RectangleFloat[] r = new RectangleFloat[6];
            r = CuboidRenderer.CuboidNet(n.sizex, n.sizey, n.sizez, n.u, n.v);
            CuboidRenderer.CuboidNetNormalize(r, m.global.texw, m.global.texh);
            GetAnimation(n, tempVec3, KeyframeType.Scale);
            if (tempVec3[0] != 0 && tempVec3[1] != 0 && tempVec3[2] != 0)
            {
                game.GLScale(tempVec3[0], tempVec3[1], tempVec3[2]);
            }
            GetAnimation(n, tempVec3, KeyframeType.Position);
            tempVec3[0] /= 16;
            tempVec3[1] /= 16;
            tempVec3[2] /= 16;
            if (!IsZero(tempVec3))
            {
                game.GLTranslate(tempVec3[0], tempVec3[1], tempVec3[2]);
            }
            GetAnimation(n, tempVec3, KeyframeType.Rotation);
            if (tempVec3[0] != 0)
            {
                game.GLRotate(tempVec3[0], 1, 0, 0);
            }
            if (tempVec3[1] != 0)
            {
                game.GLRotate(tempVec3[1], 0, 1, 0);
            }
            if (tempVec3[2] != 0)
            {
                game.GLRotate(tempVec3[2], 0, 0, 1);
            }
            if (n.head == 1)
            {
                game.GLRotate(headDeg, 1, 0, 0);
            }
            GetAnimation(n, tempVec3, KeyframeType.Pivot);
            tempVec3[0] /= 16;
            tempVec3[1] /= 16;
            tempVec3[2] /= 16;
            game.GLTranslate(tempVec3[0], tempVec3[1], tempVec3[2]);
            GetAnimation(n, tempVec3, KeyframeType.Size);
            tempVec3[0] /= 16;
            tempVec3[1] /= 16;
            tempVec3[2] /= 16;

            // Use binary minus because unary minus is truncated to integer in cito
            CuboidRenderer.DrawCuboid2(game, 0 - tempVec3[0] / 2, 0 - tempVec3[1] / 2, 0 - tempVec3[2] / 2, tempVec3[0], tempVec3[1], tempVec3[2], r, light);

            DrawNode(n.name, headDeg, light);
            game.GLPopMatrix();
        }
    }
Beispiel #22
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 #23
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();
        }