static void Main(string[] args) { // Load a document with an interactive form. PdfDocumentProcessor processor = new PdfDocumentProcessor(); processor.LoadDocument(@"DocumentToFill.pdf"); // Retrieve the form field facade: PdfDocumentFacade documentFacade = processor.DocumentFacade; PdfAcroFormFacade acroFormFacade = documentFacade.AcroForm; // Specify a checked appearance name for the Female radio button: PdfRadioGroupFormFieldFacade genderField = acroFormFacade.GetRadioGroupFormField("Gender"); foreach (PdfFormFieldItem item in genderField.Field.Items) { if (item.Value == "Female") { genderField.Value = item.Value; } } // Save the modified document. processor.SaveDocument("..\\..\\Result.pdf"); }
static void Main(string[] args) { using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor()) { pdfDocumentProcessor.LoadDocument("Documents//FormDemo.pdf"); PdfDocumentFacade documentFacade = pdfDocumentProcessor.DocumentFacade; PdfAcroFormFacade acroForm = documentFacade.AcroForm; //Change all form fields' color settings: var fields = acroForm.GetFields(); foreach (PdfFormFieldFacade field in fields) { ChangeFormFieldColor(field); } //Obtain button form field parameters: PdfButtonFormFieldFacade pushButton = acroForm.GetButtonFormField("Submit"); PdfButtonWidgetFacade buttonWidget = pushButton.Widgets[0]; //Specify a button icon and set its options: buttonWidget.SetNormalIcon("Documents//submit_3802014.png"); buttonWidget.IconOptions.FitToAnnotationBounds = true; buttonWidget.IconOptions.ScaleCondition = PdfIconScalingCircumstances.BiggerThanAnnotationRectangle; buttonWidget.TextPosition = PdfWidgetAnnotationTextPosition.NoCaption; //Obtain the text form field properties PdfTextFormFieldFacade visaField = acroForm.GetTextFormField("VisaNo"); //Divide field text into equally spaced positions: visaField.InputType = PdfTextFieldInputType.Comb; visaField.Multiline = false; //Limit the number of inserted characters: visaField.MaxLength = 8; //Enable multiline text in the text field: PdfTextFormFieldFacade addressField = acroForm.GetTextFormField("Address"); addressField.Multiline = true; addressField.Scrollable = true; addressField.SpellCheck = false; //Set the radio group value: PdfRadioGroupFormFieldFacade genderField = acroForm.GetRadioGroupFormField("Gender"); genderField.Value = genderField.Field.Items[2].Value; //Change marker style for all radio buttons: foreach (PdfRadioButtonWidgetFacade widget in genderField.Widgets) { widget.ButtonStyle = PdfAcroFormButtonStyle.Square; } //Set combo box field value: PdfComboBoxFormFieldFacade nationalityField = acroForm.GetComboBoxFormField("Nationality"); nationalityField.Value = nationalityField.Items[68].Value; //Disable user input: nationalityField.Editable = false; //Sort list items alphabetically: nationalityField.Sorted = true; pdfDocumentProcessor.SaveDocument("FormDemo_new.pdf"); Process.Start(new ProcessStartInfo("FormDemo_new.pdf") { UseShellExecute = true }); } }