1 Reply Latest reply on Apr 30, 2017 2:35 AM by Bernd Alheit

    Problem with autofill Fields in interactive pdf via C#.

    JS05

      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);
                  }