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(); } }
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(); } }
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(); } }
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(); }