public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "SubmitResetFormActions.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfPage    page    = pdf.Pages[0];
                PdfTextBox textBox = page.AddTextBox("sample_textbox", 10, 50, 100, 15);
                textBox.Text = "Hello";

                PdfCheckBox checkBox = page.AddCheckBox("sample_checkbox", 10, 70, 100, 15, "Check me");
                checkBox.Checked = true;

                PdfRadioButton radioButton = page.AddRadioButton("radio", 10, 90, 100, 15, "Select me!");
                radioButton.ExportValue = "radio1";
                radioButton.Checked     = true;

                PdfRadioButton radioButton2 = page.AddRadioButton("radio", 10, 110, 100, 15, "No, select me!");
                radioButton2.ExportValue = "radio2";
                radioButton2.Checked     = false;

                PdfButton submitButton = page.AddButton(10, 130, 45, 20);
                submitButton.Text = "Submit";
                PdfSubmitFormAction submitAction = pdf.CreateSubmitFormAction(new Uri("http://bitmiracle.com/login.php"));
                submitAction.SubmitFormat = PdfSubmitFormat.Html;
                submitAction.SubmitMethod = PdfSubmitMethod.Get;
                submitAction.AddControl(textBox);
                submitAction.AddControl(checkBox);
                submitAction.AddControl(radioButton);
                submitAction.AddControl(radioButton2);
                submitButton.OnMouseDown = submitAction;

                PdfButton resetButton = page.AddButton(65, 130, 45, 20);
                resetButton.Text = "Reset";
                PdfResetFormAction resetAction = pdf.CreateResetFormAction();
                resetAction.AddControl(textBox);
                resetAction.AddControl(checkBox);
                resetAction.AddControl(radioButton);
                resetAction.AddControl(radioButton2);
                resetButton.OnMouseDown = resetAction;

                pdf.Save(pathToFile);
            }

            Process.Start(pathToFile);
        }
        public ActionResult CreatePdf(IFormCollection collection)
        {
            // Create a PDF document
            Document pdfDocument = new Document();

            // Set license key received after purchase to use the converter in licensed mode
            // Leave it not set to use the converter in demo mode
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

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

            try
            {
                // The font used for titles in PDF document
                PdfFont titlesFont = pdfDocument.AddFont(new Font("Times New Roman", 10, FontStyle.Bold, GraphicsUnit.Point));
                // The font used for field names in PDF document
                PdfFont fieldNameFont = pdfDocument.AddFont(new Font("Times New Roman", 10, FontStyle.Regular, GraphicsUnit.Point));
                // The font used for buttons text in PDF document
                PdfFont buttonTextFont = pdfDocument.AddFont(new Font("Times New Roman", 10, FontStyle.Regular, GraphicsUnit.Point));
                // The font used for PDF form text box fields
                PdfFont textFieldFont = pdfDocument.AddFont(StdFontBaseFamily.Helvetica);
                textFieldFont.Size = 8;
                // The font used for PDF form combo box fields
                PdfFont comboBoxFieldFont = pdfDocument.AddFont(StdFontBaseFamily.Helvetica);
                comboBoxFieldFont.Size = 8;

                float xLocation = 5;
                float yLocation = 5;

                // Add document title
                TextElement      titleTextElement = new TextElement(xLocation, yLocation, "Create PDF Forms", titlesFont);
                AddElementResult addElementResult = pdfPage.AddElement(titleTextElement);

                yLocation = addElementResult.EndPageBounds.Bottom + 15;

                // Add a text box field to PDF form
                TextElement fieldNameTextElement = new TextElement(xLocation, yLocation, 60, "First name:", fieldNameFont);
                addElementResult = pdfPage.AddElement(fieldNameTextElement);
                RectangleF fieldNameRectangle     = addElementResult.EndPageBounds;
                RectangleF fieldBoundingRectangle = new RectangleF(fieldNameRectangle.Right + 10, yLocation, 150, 15);
                // Create the form field
                PdfFormTextBox textBoxField = pdfDocument.Form.AddTextBox(pdfPage, fieldBoundingRectangle, "Enter First Name", textFieldFont);
                // Set unique form field name used when the form is submitted
                textBoxField.Name = "firstName";
                // Set the form field default value
                textBoxField.DefaultValue = "A default first name";
                // Set form field style
                textBoxField.Style.BackColor = Color.AliceBlue;

                yLocation = fieldNameRectangle.Bottom + 10;

                // Add a text box field to PDF form
                fieldNameTextElement   = new TextElement(xLocation, yLocation, 60, "Last name:", fieldNameFont);
                addElementResult       = pdfPage.AddElement(fieldNameTextElement);
                fieldNameRectangle     = addElementResult.EndPageBounds;
                fieldBoundingRectangle = new RectangleF(fieldNameRectangle.Right + 10, yLocation, 150, 15);
                // Create the form field
                textBoxField = pdfDocument.Form.AddTextBox(pdfPage, fieldBoundingRectangle, "Enter Last Name", textFieldFont);
                // 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 = Color.MistyRose;

                yLocation = fieldNameRectangle.Bottom + 10;

                // Add a password text box field to PDF form
                fieldNameTextElement   = new TextElement(xLocation, yLocation, 60, "Password:"******"", textFieldFont);
                // Set unique form field name used when the form is submitted
                passwordTextBoxField.Name = "password";
                // Set form field style
                passwordTextBoxField.Style.BackColor = Color.AliceBlue;
                // Set the password mode for the text box
                passwordTextBoxField.IsPassword = true;

                yLocation = fieldNameRectangle.Bottom + 10;

                // Add a radio buttons group to PDF form
                fieldNameTextElement = new TextElement(xLocation, yLocation, 60, "Gender:", fieldNameFont);
                addElementResult     = pdfPage.AddElement(fieldNameTextElement);
                fieldNameRectangle   = addElementResult.EndPageBounds;
                // Create the radio buttons group
                PdfFormRadioButtonsGroup radioButtonsGroup = pdfDocument.Form.AddRadioButtonsGroup(pdfPage);
                // 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 = Color.AntiqueWhite;

                // Add the first radio button to group
                RectangleF radioButtonRectangle = new RectangleF(fieldNameRectangle.Right + 10, yLocation, 50, 10);
                // Create the form field
                PdfFormRadioButton radioButtonField = radioButtonsGroup.AddRadioButton(radioButtonRectangle, "male", pdfPage);

                fieldNameTextElement = new TextElement(fieldNameRectangle.Right + 22, yLocation, 30, "Male", fieldNameFont);
                pdfPage.AddElement(fieldNameTextElement);

                // Add the second radio button to group
                radioButtonRectangle = new RectangleF(fieldNameRectangle.Right + 60, yLocation, 50, 10);
                // Create the form field
                radioButtonField = radioButtonsGroup.AddRadioButton(radioButtonRectangle, "female", pdfPage);

                fieldNameTextElement = new TextElement(fieldNameRectangle.Right + 72, yLocation, 30, "Female", fieldNameFont);
                pdfPage.AddElement(fieldNameTextElement);

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

                yLocation = fieldNameRectangle.Bottom + 10;

                // Add a checkbox field to PDF form
                fieldNameTextElement   = new TextElement(xLocation, yLocation, 60, "Vehicle:", fieldNameFont);
                addElementResult       = pdfPage.AddElement(fieldNameTextElement);
                fieldNameRectangle     = addElementResult.EndPageBounds;
                fieldBoundingRectangle = new RectangleF(fieldNameRectangle.Right + 10, yLocation, 10, 10);
                // Create the form field
                PdfFormCheckBox checkBoxField = pdfDocument.Form.AddCheckBox(pdfPage, fieldBoundingRectangle);
                // Set unique form field name used when the form is submitted
                checkBoxField.Name = "haveCar";
                // Set form field style
                checkBoxField.Style.BackColor = Color.AntiqueWhite;
                // Set checkbox field checked state
                checkBoxField.Checked = true;

                fieldNameTextElement = new TextElement(fieldNameRectangle.Right + 22, yLocation, 50, "I have a car", fieldNameFont);
                pdfPage.AddElement(fieldNameTextElement);

                yLocation = fieldNameRectangle.Bottom + 10;

                // Add a combo box list field to PDF form
                fieldNameTextElement   = new TextElement(xLocation, yLocation, 60, "Vehicle Type:", fieldNameFont);
                addElementResult       = pdfPage.AddElement(fieldNameTextElement);
                fieldNameRectangle     = addElementResult.EndPageBounds;
                fieldBoundingRectangle = new RectangleF(fieldNameRectangle.Right + 10, yLocation, 50, 15);
                string[] comboBoxItems = new string[] { "Volvo", "Saab", "Audi", "Opel" };
                // Create the form field
                PdfFormComboBox comboBoxField = pdfDocument.Form.AddComboBox(pdfPage, fieldBoundingRectangle, comboBoxItems, comboBoxFieldFont);
                // 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 = Color.LightCyan;
                // Set selected item in combo box
                comboBoxField.Value = "Audi";

                yLocation = fieldNameRectangle.Bottom + 10;

                // Add a multiline text box field to PDF form
                fieldNameTextElement   = new TextElement(xLocation, yLocation + 20, 60, "Comments:", fieldNameFont);
                addElementResult       = pdfPage.AddElement(fieldNameTextElement);
                fieldNameRectangle     = addElementResult.EndPageBounds;
                fieldBoundingRectangle = new RectangleF(fieldNameRectangle.Right + 10, yLocation, 150, 60);
                // Create the form field
                PdfFormTextBox multilineTextBoxField = pdfDocument.Form.AddTextBox(pdfPage, fieldBoundingRectangle,
                                                                                   "Enter your comments here:\r\nFirst comment line\r\nSecond comment line", textFieldFont);
                // Set unique form field name used when the form is submitted
                multilineTextBoxField.Name = "comments";
                // Set form field style
                multilineTextBoxField.Style.BackColor = Color.AliceBlue;
                // Set the multiline mode for text box field
                multilineTextBoxField.IsMultiLine = true;

                yLocation = yLocation + 70;

                // Add a form submit button to PDF form
                fieldBoundingRectangle = new RectangleF(xLocation, yLocation, 75, 15);
                PdfFormButton submitFormButton = pdfDocument.Form.AddButton(pdfPage, fieldBoundingRectangle, "Submit", buttonTextFont);
                // Set unique form field name used when the form is submitted
                submitFormButton.Name = "submitFormButton";
                // Set form field style
                submitFormButton.Style.BackColor = Color.Beige;
                // Create the form submit action
                PdfSubmitFormAction submitFormAction = new PdfSubmitFormAction(collection["submitUrlTextBox"]);
                // Form values will be submitted in HTML form format
                submitFormAction.Flags |= PdfFormSubmitFlags.ExportFormat;
                if (collection["HttpMethod"] == "getMethodRadioButton")
                {
                    submitFormAction.Flags |= PdfFormSubmitFlags.GetMethod;
                }
                // Set the form submit button action
                submitFormButton.Action = submitFormAction;

                // Add a form reset button to PDF form
                fieldBoundingRectangle = new RectangleF(xLocation + 100, yLocation, 75, 15);
                PdfFormButton resetFormButton = pdfDocument.Form.AddButton(pdfPage, fieldBoundingRectangle, "Reset", buttonTextFont);
                // Set unique form field name used when the form is submitted
                resetFormButton.Name = "resetFormButton";
                // Set form field style
                resetFormButton.Style.BackColor = Color.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 file to browser
                FileResult fileResult = new FileContentResult(outPdfBuffer, "application/pdf");
                fileResult.FileDownloadName = "Create_PDF_Forms.pdf";

                return(fileResult);
            }
            finally
            {
                // Close the PDF document
                pdfDocument.Close();
            }
        }
        public ActionResult CreatePdf(FormCollection collection)
        {
            // create a PDF document
            PdfDocument document = new PdfDocument();

            // set a demo serial number
            document.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // add a page to document
            PdfPage page = document.AddPage();

            // create true type fonts that can be used in document
            System.Drawing.Font ttfFont      = new System.Drawing.Font("Times New Roman", 10, System.Drawing.GraphicsUnit.Point);
            PdfFont             newTimesFont = document.CreateFont(ttfFont, false);

            // create a standard font that can be used in document
            PdfFont helveticaStd = document.CreateStandardFont(PdfStandardFont.Helvetica);

            helveticaStd.Size = 10;

            float crtXPos = 10;
            float crtYPos = 10;

            #region Add Check Box Field

            if (collection["checkBoxAddCheckBox"] != null)
            {
                // add a check box field to PDF form
                PdfFormCheckBox checkBoxField = document.Form.AddCheckBox(page, new System.Drawing.RectangleF(crtXPos, crtYPos, 10, 10));

                checkBoxField.Checked = collection["checkBoxCheckedState"] != null;

                // common field properties
                checkBoxField.Name     = "cb";
                checkBoxField.ToolTip  = "Click to change the checked state";
                checkBoxField.Required = false;
                checkBoxField.ReadOnly = false;
                checkBoxField.Flatten  = false;

                // advance the current drawing position in PDF page
                crtYPos = checkBoxField.BoundingRectangle.Bottom + 5;
            }

            #endregion

            #region Add Text Box Field

            if (collection["checkBoxAddTextBox"] != null)
            {
                string         initialText  = collection["textBoxInitialText"];
                PdfFormTextBox textBoxField = document.Form.AddTextBox(page, new System.Drawing.RectangleF(crtXPos, crtYPos, 300, 50), initialText, newTimesFont);

                textBoxField.IsMultiLine = collection["checkBoxMultiline"] != null;
                textBoxField.IsPassword  = collection["checkBoxIsPassword"] != null;

                textBoxField.Style.ForeColor   = System.Drawing.Color.Navy;
                textBoxField.Style.BackColor   = System.Drawing.Color.WhiteSmoke;
                textBoxField.Style.BorderStyle = PdfBorderStyle.FixedSingle;
                textBoxField.Style.BorderColor = System.Drawing.Color.Green;

                // common field properties
                textBoxField.Name         = "tb";
                textBoxField.ToolTip      = "Please enter some text";
                textBoxField.Required     = false;
                textBoxField.ReadOnly     = false;
                textBoxField.DefaultValue = "Default text";
                textBoxField.Flatten      = false;

                // advance the current drawing position in PDF page
                crtYPos = textBoxField.BoundingRectangle.Bottom + 5;
            }

            #endregion

            #region Add  List Box Field

            if (collection["checkBoxAddListBox"] != null)
            {
                string[] listValues = collection["textBoxListBoxValues"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                PdfFormListBox listBoxField = document.Form.AddListBox(page, new System.Drawing.RectangleF(crtXPos, crtYPos, 300, 50), listValues, helveticaStd);

                // common field properties
                listBoxField.Name     = "lb";
                listBoxField.ToolTip  = "Select an element from the list";
                listBoxField.Required = false;
                listBoxField.ReadOnly = false;
                if (listValues.Length > 0)
                {
                    listBoxField.DefaultValue = listValues[0];
                }
                listBoxField.Flatten = false;

                // advance the current drawing position in PDF page
                crtYPos = listBoxField.BoundingRectangle.Bottom + 5;
            }

            #endregion

            #region Add Combo Box Field

            if (collection["checkBoxAddComboBox"] != null)
            {
                string[] listValues = collection["textBoxComboBoxValues"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                PdfFormComboBox comboBoxField = document.Form.AddComboBox(page, new System.Drawing.RectangleF(crtXPos, crtYPos, 300, 15), listValues, helveticaStd);

                comboBoxField.Editable = collection["checkBoxEditableCombo"] != null;

                // common field properties
                comboBoxField.Name     = "combo";
                comboBoxField.ToolTip  = "Select an element from the combo drop down";
                comboBoxField.Required = false;
                comboBoxField.ReadOnly = false;
                if (listValues.Length > 0)
                {
                    comboBoxField.DefaultValue = listValues[0];
                }
                comboBoxField.Flatten = false;

                // advance the current drawing position in PDF page
                crtYPos = comboBoxField.BoundingRectangle.Bottom + 5;
            }

            #endregion

            #region Add Radio Buttons Group Field

            if (collection["checkBoxAddRadioButtons"] != null)
            {
                PdfFormRadioButtonsGroup radioGroup = document.Form.AddRadioButtonsGroup(page);

                PdfFormRadioButton rb1 = radioGroup.AddRadioButton(new System.Drawing.RectangleF(crtXPos, crtYPos, 10, 10), "rb1");
                PdfFormRadioButton rb2 = radioGroup.AddRadioButton(new System.Drawing.RectangleF(crtXPos + 20, crtYPos, 10, 10), "rb2");

                radioGroup.SetCheckedRadioButton(rb2);

                radioGroup.Name = "rg";

                // advance the current drawing position in PDF page
                crtYPos = rb1.BoundingRectangle.Bottom + 20;
            }

            #endregion

            #region Create the Submit Button

            // create the Submit button
            PdfFormButton submitButton = document.Form.AddButton(page, new System.Drawing.RectangleF(crtXPos, crtYPos, 100, 20), "Submit Form", newTimesFont);
            submitButton.Name = "submitButton";

            // create the submit action with the submit URL
            PdfSubmitFormAction submitAction = new PdfSubmitFormAction(collection["textBoxSubmitUrl"]);
            // set the action flags such that the form values are submitted in HTML form format
            submitAction.Flags |= PdfFormSubmitFlags.ExportFormat;
            if (collection["SubmitMethod"] == "radioButtonGet")
            {
                submitAction.Flags |= PdfFormSubmitFlags.GetMethod;
            }

            // set the submit button action
            submitButton.Action = submitAction;

            #endregion

            #region Create the Reset Button

            if (collection["checkBoxAddResetButton"] != null)
            {
                // create the reset button
                PdfFormButton resetButton = document.Form.AddButton(page, new System.Drawing.RectangleF(crtXPos + 120, crtYPos, 100, 20),
                                                                    "Reset Form", newTimesFont);
                resetButton.Name = "resetButton";

                // create the reset action
                PdfResetFormAction resetAction = new PdfResetFormAction();

                // set the reset button action
                resetButton.Action = resetAction;
            }

            #endregion

            try
            {
                // write the PDF document to a memory buffer
                byte[] pdfBuffer = document.WriteToMemory();

                FileResult fileResult = new FileContentResult(pdfBuffer, "application/pdf");
                fileResult.FileDownloadName = "CreateForms.pdf";

                return(fileResult);
            }
            finally
            {
                document.Close();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run()
        {
            PdfFixedDocument document = new PdfFixedDocument();
            PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 12);
            PdfBrush brush = new PdfBrush();

            PdfPage page = document.Pages.Add();

            // First name
            page.Graphics.DrawString("First name:", helvetica, brush, 50, 50);
            PdfTextBoxField firstNameTextBox = new PdfTextBoxField("firstname");
            page.Fields.Add(firstNameTextBox);
            firstNameTextBox.Widgets[0].Font = helvetica;
            firstNameTextBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 45, 200, 20);
            firstNameTextBox.Widgets[0].BorderColor = PdfRgbColor.Black;
            firstNameTextBox.Widgets[0].BorderWidth = 1;

            // Last name
            page.Graphics.DrawString("Last name:", helvetica, brush, 50, 80);
            PdfTextBoxField lastNameTextBox = new PdfTextBoxField("lastname");
            page.Fields.Add(lastNameTextBox);
            lastNameTextBox.Widgets[0].Font = helvetica;
            lastNameTextBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 75, 200, 20);
            lastNameTextBox.Widgets[0].BorderColor = PdfRgbColor.Black;
            lastNameTextBox.Widgets[0].BorderWidth = 1;

            // Sex
            page.Graphics.DrawString("Sex:", helvetica, brush, 50, 110);
            PdfRadioButtonField sexRadioButton = new PdfRadioButtonField("sex");
            PdfRadioButtonWidget maleRadioItem = new PdfRadioButtonWidget();
            sexRadioButton.Widgets.Add(maleRadioItem);
            PdfRadioButtonWidget femaleRadioItem = new PdfRadioButtonWidget();
            sexRadioButton.Widgets.Add(femaleRadioItem);
            page.Fields.Add(sexRadioButton);

            page.Graphics.DrawString("Male", helvetica, brush, 180, 110);
            maleRadioItem.ExportValue = "M";
            maleRadioItem.CheckStyle = PdfCheckStyle.Circle;
            maleRadioItem.VisualRectangle = new PdfVisualRectangle(150, 105, 20, 20);
            maleRadioItem.BorderColor = PdfRgbColor.Black;
            maleRadioItem.BorderWidth = 1;

            page.Graphics.DrawString("Female", helvetica, brush, 280, 110);
            femaleRadioItem.ExportValue = "F";
            femaleRadioItem.CheckStyle = PdfCheckStyle.Circle;
            femaleRadioItem.VisualRectangle = new PdfVisualRectangle(250, 105, 20, 20);
            femaleRadioItem.BorderColor = PdfRgbColor.Black;
            femaleRadioItem.BorderWidth = 1;

            // First car
            page.Graphics.DrawString("First car:", helvetica, brush, 50, 140);
            PdfComboBoxField firstCarList = new PdfComboBoxField("firstcar");
            firstCarList.Items.Add(new PdfListItem("Mercedes", "Mercedes"));
            firstCarList.Items.Add(new PdfListItem("BMW", "BMW"));
            firstCarList.Items.Add(new PdfListItem("Audi", "Audi"));
            firstCarList.Items.Add(new PdfListItem("Volkswagen", "Volkswagen"));
            firstCarList.Items.Add(new PdfListItem("Porsche", "Porsche"));
            firstCarList.Items.Add(new PdfListItem("Honda", "Honda"));
            firstCarList.Items.Add(new PdfListItem("Toyota", "Toyota"));
            firstCarList.Items.Add(new PdfListItem("Lexus", "Lexus"));
            firstCarList.Items.Add(new PdfListItem("Infiniti", "Infiniti"));
            firstCarList.Items.Add(new PdfListItem("Acura", "Acura"));
            page.Fields.Add(firstCarList);
            firstCarList.Widgets[0].Font = helvetica;
            firstCarList.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 135, 200, 20);
            firstCarList.Widgets[0].BorderColor = PdfRgbColor.Black;
            firstCarList.Widgets[0].BorderWidth = 1;

            // Second car
            page.Graphics.DrawString("Second car:", helvetica, brush, 50, 170);
            PdfListBoxField secondCarList = new PdfListBoxField("secondcar");
            secondCarList.Items.Add(new PdfListItem("Mercedes", "Mercedes"));
            secondCarList.Items.Add(new PdfListItem("BMW", "BMW"));
            secondCarList.Items.Add(new PdfListItem("Audi", "Audi"));
            secondCarList.Items.Add(new PdfListItem("Volkswagen", "Volkswagen"));
            secondCarList.Items.Add(new PdfListItem("Porsche", "Porsche"));
            secondCarList.Items.Add(new PdfListItem("Honda", "Honda"));
            secondCarList.Items.Add(new PdfListItem("Toyota", "Toyota"));
            secondCarList.Items.Add(new PdfListItem("Lexus", "Lexus"));
            secondCarList.Items.Add(new PdfListItem("Infiniti", "Infiniti"));
            secondCarList.Items.Add(new PdfListItem("Acura", "Acura"));
            page.Fields.Add(secondCarList);
            secondCarList.Widgets[0].Font = helvetica;
            secondCarList.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 165, 200, 60);
            secondCarList.Widgets[0].BorderColor = PdfRgbColor.Black;
            secondCarList.Widgets[0].BorderWidth = 1;

            // I agree
            page.Graphics.DrawString("I agree:", helvetica, brush, 50, 240);
            PdfCheckBoxField agreeCheckBox = new PdfCheckBoxField("agree");
            page.Fields.Add(agreeCheckBox);
            agreeCheckBox.Widgets[0].Font = helvetica;
            (agreeCheckBox.Widgets[0] as PdfCheckWidget).ExportValue = "YES";
            (agreeCheckBox.Widgets[0] as PdfCheckWidget).CheckStyle = PdfCheckStyle.Check;
            agreeCheckBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 235, 20, 20);
            agreeCheckBox.Widgets[0].BorderColor = PdfRgbColor.Black;
            agreeCheckBox.Widgets[0].BorderWidth = 1;

            // Sign here
            page.Graphics.DrawString("Sign here:", helvetica, brush, 50, 270);
            PdfSignatureField signHereField = new PdfSignatureField("signhere");
            page.Fields.Add(signHereField);
            signHereField.Widgets[0].Font = helvetica;
            signHereField.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 265, 200, 60);

            // Submit form
            PdfPushButtonField submitBtn = new PdfPushButtonField("submit");
            page.Fields.Add(submitBtn);
            submitBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 45, 150, 30);
            (submitBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Submit form";
            submitBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray;
            PdfSubmitFormAction submitFormAction = new PdfSubmitFormAction();
            submitFormAction.DataFormat = PdfSubmitDataFormat.FDF;
            submitFormAction.Fields.Add("firstname");
            submitFormAction.Fields.Add("lastname");
            submitFormAction.Fields.Add("sex");
            submitFormAction.Fields.Add("firstcar");
            submitFormAction.Fields.Add("secondcar");
            submitFormAction.Fields.Add("agree");
            submitFormAction.Fields.Add("signhere");
            submitFormAction.SubmitFields = true;
            submitFormAction.Url = "http://www.xfiniumsoft.com/";
            submitBtn.Widgets[0].MouseUp = submitFormAction;

            // Reset form
            PdfPushButtonField resetBtn = new PdfPushButtonField("reset");
            page.Fields.Add(resetBtn);
            resetBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 85, 150, 30);
            (resetBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Reset form";
            resetBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray;
            PdfResetFormAction resetFormAction = new PdfResetFormAction();
            resetBtn.Widgets[0].MouseUp = resetFormAction;

            // Print form
            PdfPushButtonField printBtn = new PdfPushButtonField("print");
            page.Fields.Add(printBtn);
            printBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 125, 150, 30);
            (printBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Print form";
            printBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray;
            PdfJavaScriptAction printAction = new PdfJavaScriptAction();
            printAction.Script = "this.print(true);\n";
            printBtn.Widgets[0].MouseUp = printAction;

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.formgenerator.pdf") };
            return output;
        }
Beispiel #5
0
        protected void buttonCreatePdf_Click(object sender, EventArgs e)
        {
            // create a PDF document
            PdfDocument document = new PdfDocument();

            // set a demo serial number
            document.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // add a page to document
            PdfPage page = document.AddPage();

            // create true type fonts that can be used in document
            System.Drawing.Font ttfFont      = new System.Drawing.Font("Times New Roman", 10, System.Drawing.GraphicsUnit.Point);
            PdfFont             newTimesFont = document.CreateFont(ttfFont, false);

            // create a standard font that can be used in document
            PdfFont helveticaStd = document.CreateStandardFont(PdfStandardFont.Helvetica);

            helveticaStd.Size = 10;

            float crtXPos = 10;
            float crtYPos = 10;

            #region Add Check Box Field

            if (checkBoxAddCheckBox.Checked)
            {
                // add a check box field to PDF form
                PdfFormCheckBox checkBoxField = document.Form.AddCheckBox(page, new System.Drawing.RectangleF(crtXPos, crtYPos, 10, 10));

                checkBoxField.Checked = checkBoxCheckedState.Checked;

                // common field properties
                checkBoxField.Name     = "cb";
                checkBoxField.ToolTip  = "Click to change the checked state";
                checkBoxField.Required = false;
                checkBoxField.ReadOnly = false;
                checkBoxField.Flatten  = false;

                // advance the current drawing position in PDF page
                crtYPos = checkBoxField.BoundingRectangle.Bottom + 5;
            }

            #endregion

            #region Add Text Box Field

            if (checkBoxAddTextBox.Checked)
            {
                string         initialText  = textBoxInitialText.Text;
                PdfFormTextBox textBoxField = document.Form.AddTextBox(page, new System.Drawing.RectangleF(crtXPos, crtYPos, 300, 50), initialText, newTimesFont);

                textBoxField.IsMultiLine = checkBoxMultiline.Checked;
                textBoxField.IsPassword  = checkBoxIsPassword.Checked;

                textBoxField.Style.ForeColor   = System.Drawing.Color.Navy;
                textBoxField.Style.BackColor   = System.Drawing.Color.WhiteSmoke;
                textBoxField.Style.BorderStyle = PdfBorderStyle.FixedSingle;
                textBoxField.Style.BorderColor = System.Drawing.Color.Green;

                // common field properties
                textBoxField.Name         = "tb";
                textBoxField.ToolTip      = "Please enter some text";
                textBoxField.Required     = false;
                textBoxField.ReadOnly     = false;
                textBoxField.DefaultValue = "Default text";
                textBoxField.Flatten      = false;

                // advance the current drawing position in PDF page
                crtYPos = textBoxField.BoundingRectangle.Bottom + 5;
            }

            #endregion

            #region Add  List Box Field

            if (checkBoxAddListBox.Checked)
            {
                string[] listValues = textBoxListBoxValues.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                PdfFormListBox listBoxField = document.Form.AddListBox(page, new System.Drawing.RectangleF(crtXPos, crtYPos, 300, 50), listValues, helveticaStd);

                // common field properties
                listBoxField.Name     = "lb";
                listBoxField.ToolTip  = "Select an element from the list";
                listBoxField.Required = false;
                listBoxField.ReadOnly = false;
                if (listValues.Length > 0)
                {
                    listBoxField.DefaultValue = listValues[0];
                }
                listBoxField.Flatten = false;

                // advance the current drawing position in PDF page
                crtYPos = listBoxField.BoundingRectangle.Bottom + 5;
            }

            #endregion

            #region Add Combo Box Field

            if (checkBoxAddComboBox.Checked)
            {
                string[] listValues = textBoxComboBoxValues.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                PdfFormComboBox comboBoxField = document.Form.AddComboBox(page, new System.Drawing.RectangleF(crtXPos, crtYPos, 300, 15), listValues, helveticaStd);

                comboBoxField.Editable = checkBoxEditableCombo.Checked;

                // common field properties
                comboBoxField.Name     = "combo";
                comboBoxField.ToolTip  = "Select an element from the combo drop down";
                comboBoxField.Required = false;
                comboBoxField.ReadOnly = false;
                if (listValues.Length > 0)
                {
                    comboBoxField.DefaultValue = listValues[0];
                }
                comboBoxField.Flatten = false;

                // advance the current drawing position in PDF page
                crtYPos = comboBoxField.BoundingRectangle.Bottom + 5;
            }

            #endregion

            #region Add Radio Buttons Group Field

            if (checkBoxAddRadioButtons.Checked)
            {
                PdfFormRadioButtonsGroup radioGroup = document.Form.AddRadioButtonsGroup(page);

                PdfFormRadioButton rb1 = radioGroup.AddRadioButton(new System.Drawing.RectangleF(crtXPos, crtYPos, 10, 10), "rb1");
                PdfFormRadioButton rb2 = radioGroup.AddRadioButton(new System.Drawing.RectangleF(crtXPos + 20, crtYPos, 10, 10), "rb2");

                radioGroup.SetCheckedRadioButton(rb2);

                radioGroup.Name = "rg";

                // advance the current drawing position in PDF page
                crtYPos = rb1.BoundingRectangle.Bottom + 20;
            }

            #endregion

            #region Create the Submit Button

            // create the Submit button
            PdfFormButton submitButton = document.Form.AddButton(page, new System.Drawing.RectangleF(crtXPos, crtYPos, 100, 20), "Submit Form", newTimesFont);
            submitButton.Name = "submitButton";

            // create the submit action with the submit URL
            PdfSubmitFormAction submitAction = new PdfSubmitFormAction(textBoxSubmitUrl.Text);
            // set the action flags such that the form values are submitted in HTML form format
            submitAction.Flags |= PdfFormSubmitFlags.ExportFormat;
            if (radioButtonGet.Checked)
            {
                submitAction.Flags |= PdfFormSubmitFlags.GetMethod;
            }

            // set the submit button action
            submitButton.Action = submitAction;

            #endregion

            #region Create the Reset Button

            if (checkBoxAddResetButton.Checked)
            {
                // create the reset button
                PdfFormButton resetButton = document.Form.AddButton(page, new System.Drawing.RectangleF(crtXPos + 120, crtYPos, 100, 20),
                                                                    "Reset Form", newTimesFont);
                resetButton.Name = "resetButton";

                // create the reset action
                PdfResetFormAction resetAction = new PdfResetFormAction();

                // set the reset button action
                resetButton.Action = resetAction;
            }

            #endregion

            try
            {
                // write the PDF document to a memory buffer
                byte[] pdfBuffer = document.WriteToMemory();

                // inform the browser about the binary data format
                HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");

                // let the browser know how to open the PDF document and the file name
                HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=CreateForms.pdf; size={0}",
                                                                                            pdfBuffer.Length.ToString()));

                // write the PDF buffer to HTTP response
                HttpContext.Current.Response.BinaryWrite(pdfBuffer);

                // call End() method of HTTP response to stop ASP.NET page processing
                HttpContext.Current.Response.End();
            }
            finally
            {
                document.Close();
            }
        }
Beispiel #6
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run()
        {
            PdfFixedDocument document  = new PdfFixedDocument();
            PdfStandardFont  helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 12);
            PdfBrush         brush     = new PdfBrush();

            PdfPage page = document.Pages.Add();

            // First name
            page.Graphics.DrawString("First name:", helvetica, brush, 50, 50);
            PdfTextBoxField firstNameTextBox = new PdfTextBoxField("firstname");

            page.Fields.Add(firstNameTextBox);
            firstNameTextBox.Widgets[0].Font            = helvetica;
            firstNameTextBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 45, 200, 20);
            firstNameTextBox.Widgets[0].BorderColor     = PdfRgbColor.Black;
            firstNameTextBox.Widgets[0].BorderWidth     = 1;

            // Last name
            page.Graphics.DrawString("Last name:", helvetica, brush, 50, 80);
            PdfTextBoxField lastNameTextBox = new PdfTextBoxField("lastname");

            page.Fields.Add(lastNameTextBox);
            lastNameTextBox.Widgets[0].Font            = helvetica;
            lastNameTextBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 75, 200, 20);
            lastNameTextBox.Widgets[0].BorderColor     = PdfRgbColor.Black;
            lastNameTextBox.Widgets[0].BorderWidth     = 1;

            // Sex
            page.Graphics.DrawString("Sex:", helvetica, brush, 50, 110);
            PdfRadioButtonField  sexRadioButton = new PdfRadioButtonField("sex");
            PdfRadioButtonWidget maleRadioItem  = new PdfRadioButtonWidget();

            sexRadioButton.Widgets.Add(maleRadioItem);
            PdfRadioButtonWidget femaleRadioItem = new PdfRadioButtonWidget();

            sexRadioButton.Widgets.Add(femaleRadioItem);
            page.Fields.Add(sexRadioButton);

            page.Graphics.DrawString("Male", helvetica, brush, 180, 110);
            maleRadioItem.ExportValue     = "M";
            maleRadioItem.CheckStyle      = PdfCheckStyle.Circle;
            maleRadioItem.VisualRectangle = new PdfVisualRectangle(150, 105, 20, 20);
            maleRadioItem.BorderColor     = PdfRgbColor.Black;
            maleRadioItem.BorderWidth     = 1;

            page.Graphics.DrawString("Female", helvetica, brush, 280, 110);
            femaleRadioItem.ExportValue     = "F";
            femaleRadioItem.CheckStyle      = PdfCheckStyle.Circle;
            femaleRadioItem.VisualRectangle = new PdfVisualRectangle(250, 105, 20, 20);
            femaleRadioItem.BorderColor     = PdfRgbColor.Black;
            femaleRadioItem.BorderWidth     = 1;

            // First car
            page.Graphics.DrawString("First car:", helvetica, brush, 50, 140);
            PdfComboBoxField firstCarList = new PdfComboBoxField("firstcar");

            firstCarList.Items.Add(new PdfListItem("Mercedes", "Mercedes"));
            firstCarList.Items.Add(new PdfListItem("BMW", "BMW"));
            firstCarList.Items.Add(new PdfListItem("Audi", "Audi"));
            firstCarList.Items.Add(new PdfListItem("Volkswagen", "Volkswagen"));
            firstCarList.Items.Add(new PdfListItem("Porsche", "Porsche"));
            firstCarList.Items.Add(new PdfListItem("Honda", "Honda"));
            firstCarList.Items.Add(new PdfListItem("Toyota", "Toyota"));
            firstCarList.Items.Add(new PdfListItem("Lexus", "Lexus"));
            firstCarList.Items.Add(new PdfListItem("Infiniti", "Infiniti"));
            firstCarList.Items.Add(new PdfListItem("Acura", "Acura"));
            page.Fields.Add(firstCarList);
            firstCarList.Widgets[0].Font            = helvetica;
            firstCarList.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 135, 200, 20);
            firstCarList.Widgets[0].BorderColor     = PdfRgbColor.Black;
            firstCarList.Widgets[0].BorderWidth     = 1;

            // Second car
            page.Graphics.DrawString("Second car:", helvetica, brush, 50, 170);
            PdfListBoxField secondCarList = new PdfListBoxField("secondcar");

            secondCarList.Items.Add(new PdfListItem("Mercedes", "Mercedes"));
            secondCarList.Items.Add(new PdfListItem("BMW", "BMW"));
            secondCarList.Items.Add(new PdfListItem("Audi", "Audi"));
            secondCarList.Items.Add(new PdfListItem("Volkswagen", "Volkswagen"));
            secondCarList.Items.Add(new PdfListItem("Porsche", "Porsche"));
            secondCarList.Items.Add(new PdfListItem("Honda", "Honda"));
            secondCarList.Items.Add(new PdfListItem("Toyota", "Toyota"));
            secondCarList.Items.Add(new PdfListItem("Lexus", "Lexus"));
            secondCarList.Items.Add(new PdfListItem("Infiniti", "Infiniti"));
            secondCarList.Items.Add(new PdfListItem("Acura", "Acura"));
            page.Fields.Add(secondCarList);
            secondCarList.Widgets[0].Font            = helvetica;
            secondCarList.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 165, 200, 60);
            secondCarList.Widgets[0].BorderColor     = PdfRgbColor.Black;
            secondCarList.Widgets[0].BorderWidth     = 1;

            // I agree
            page.Graphics.DrawString("I agree:", helvetica, brush, 50, 240);
            PdfCheckBoxField agreeCheckBox = new PdfCheckBoxField("agree");

            page.Fields.Add(agreeCheckBox);
            agreeCheckBox.Widgets[0].Font = helvetica;
            (agreeCheckBox.Widgets[0] as PdfCheckWidget).ExportValue = "YES";
            (agreeCheckBox.Widgets[0] as PdfCheckWidget).CheckStyle  = PdfCheckStyle.Check;
            agreeCheckBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 235, 20, 20);
            agreeCheckBox.Widgets[0].BorderColor     = PdfRgbColor.Black;
            agreeCheckBox.Widgets[0].BorderWidth     = 1;

            // Sign here
            page.Graphics.DrawString("Sign here:", helvetica, brush, 50, 270);
            PdfSignatureField signHereField = new PdfSignatureField("signhere");

            page.Fields.Add(signHereField);
            signHereField.Widgets[0].Font            = helvetica;
            signHereField.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 265, 200, 60);

            // Submit form
            PdfPushButtonField submitBtn = new PdfPushButtonField("submit");

            page.Fields.Add(submitBtn);
            submitBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 45, 150, 30);
            (submitBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Submit form";
            submitBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray;
            PdfSubmitFormAction submitFormAction = new PdfSubmitFormAction();

            submitFormAction.DataFormat = PdfSubmitDataFormat.FDF;
            submitFormAction.Fields.Add("firstname");
            submitFormAction.Fields.Add("lastname");
            submitFormAction.Fields.Add("sex");
            submitFormAction.Fields.Add("firstcar");
            submitFormAction.Fields.Add("secondcar");
            submitFormAction.Fields.Add("agree");
            submitFormAction.Fields.Add("signhere");
            submitFormAction.SubmitFields = true;
            submitFormAction.Url          = "http://www.xfiniumsoft.com/";
            submitBtn.Widgets[0].MouseUp  = submitFormAction;

            // Reset form
            PdfPushButtonField resetBtn = new PdfPushButtonField("reset");

            page.Fields.Add(resetBtn);
            resetBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 85, 150, 30);
            (resetBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Reset form";
            resetBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray;
            PdfResetFormAction resetFormAction = new PdfResetFormAction();

            resetBtn.Widgets[0].MouseUp = resetFormAction;

            // Print form
            PdfPushButtonField printBtn = new PdfPushButtonField("print");

            page.Fields.Add(printBtn);
            printBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 125, 150, 30);
            (printBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Print form";
            printBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray;
            PdfJavaScriptAction printAction = new PdfJavaScriptAction();

            printAction.Script          = "this.print(true);\n";
            printBtn.Widgets[0].MouseUp = printAction;

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.formgenerator.pdf") };
            return(output);
        }
        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();
        }