Exemplo n.º 1
0
        static void Main(string[] args)
        {
            String FORM_NAME = Application.StartupPath + "\\..\\..\\..\\..\\..\\TestFiles\\SampleForm.pdf";
            // Initialize Acrobat by cretaing App object.
            CAcroApp acroApp = new AcroAppClass();

            // Show Acrobat Viewer
            acroApp.Show();

            // Create an AVDoc object
            CAcroAVDoc avDoc = new AcroAVDocClass();

            // Open the pdf
            if (!avDoc.Open(FORM_NAME, ""))
            {
                string szMsg = "Cannot open" + FORM_NAME + ".\n";
                Console.WriteLine(szMsg);
                return;
            }

            // Create a IAFormApp object, so that we can access the form fields in
            // the open document
            IAFormApp formApp = new AFormAppClass();

            // Get the IFields object associated with the form
            IFields myFields = (IFields)formApp.Fields;

            // Get the IEnumerator object for myFields
            IEnumerator myEnumerator = myFields.GetEnumerator();

            bool bFound = false;

            // Fill the "Name" field with value "John Doe"
            while (myEnumerator.MoveNext())
            {
                // Get the IField object
                IField myField = (IField)myEnumerator.Current;

                // If the field is "Name", set it's value to "John Doe"
                if (myField.Name == "Name")
                {
                    bFound        = true;
                    myField.Value = "John Doe";
                    break;
                }
            }

            if (bFound)
            {
                Console.WriteLine("Sucessfully changed the \"Name\" field value to \"John Doe\".");
            }
            else
            {
                Console.WriteLine("Failed to locate the \"Name\" field in the form.");
            }
        }