static void Main(string[] args) { const float dpix = 72f; const float dpiY = 72f; using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) { // Load a PDF document with AcroForm data. processor.LoadDocument("..\\..\\InteractiveForm.pdf"); PdfDocumentFacade documentFacade = processor.DocumentFacade; PdfAcroFormFacade acroForm = documentFacade.AcroForm; string fieldName = "Address"; PdfTextFormFieldFacade formField = acroForm.GetFormField(fieldName) as PdfTextFormFieldFacade; if (formField == null) { return; } foreach (PdfWidgetFacade widget in formField) { PdfRectangle rect = widget.Rectangle; PdfPage page = processor.Document.Pages[widget.PageNumber - 1]; double x = rect.Left - page.CropBox.Left; double y = page.CropBox.Top - rect.Bottom; // Create graphics and draw an image. using (PdfGraphics graphics = processor.CreateGraphics()) { DrawImage(graphics, rect, x, y); graphics.AddToPageForeground(page, dpix, dpiY); } } processor.RemoveFormField(fieldName); 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 }); } }