Skip to main content
JS05
Participant
January 13, 2017
Question

Problem with autofill Fields in interactive pdf via C#.

  • January 13, 2017
  • 1 reply
  • 349 views

Hello,

I have problem with autofill Fields in interactive pdf via C#.

Method myFields.GetEnumerator() returns empty enumerator.

IEnumerator myEnumerator = myFields.GetEnumerator();

           String FORM_NAME = Application.StartupPath + "\\PIT-11(23)_v1-0E_2016.pdf";

           

            CAcroApp acroApp = new AcroAppClass();           

            acroApp.Show();

            CAcroAVDoc avDoc = new AcroAVDocClass();

            // Open the pdf

            if (!avDoc.Open(FORM_NAME, ""))

            {

                string szMsg = "Cannot open" + FORM_NAME + ".\n";

                Console.WriteLine(szMsg);

                return;

            }

           

            try

            {

                // Create a IAFormApp object, so that we can access the form fields in  the open document

                IAFormApp formApp = new AFormAppClass();

                IFields myFields = (IFields)formApp.Fields;

                IEnumerator myEnumerator = myFields.GetEnumerator();//EMPTY ENUMERATOR!!!!!

                while (myEnumerator.MoveNext())

                {

                    IField myField = (IField)myEnumerator.Current;

                    // If the field is "Name", set it's value to "John Doe"

                    if (myField.Name == "Name")

                    {

                        myField.Value = "John Doe";

                        break;

                    }

                }

                return;

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

This topic has been closed for replies.

1 reply

Bernd Alheit
Community Expert
Community Expert
April 30, 2017

Are there form fields in the document?