示例#1
0
        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");
        }
示例#2
0
        static void Main(string[] args)
        {
            // Load a document with an interactive form.
            PdfDocumentProcessor processor = new PdfDocumentProcessor();

            processor.LoadDocument("..\\..\\InteractiveForm.pdf");

            PdfDocumentFacade documentFacade = processor.DocumentFacade;
            PdfAcroFormFacade acroForm       = documentFacade.AcroForm;

            // Obtain the check box form field:
            PdfCheckBoxFormFieldFacade genderField = acroForm.GetCheckBoxFormField("Female");

            // Specify a checked value for the Female form field:
            genderField.IsChecked = true;

            // Save the modified document.
            processor.SaveDocument("..\\..\\Result.pdf");
        }
        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");
            }
        }
示例#4
0
        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
                });
            }
        }