GetFieldFacade gives Index out of range

I’m receiving an Index out of range error trying to read the field facade. I’ve included a sample project where you can add a license, and set breakpoints here:
//TODO Set breakpoint here

1 Like

@gmitchell.ipipeline

The “Index out of range” error you are encountering when trying to read the field facade typically occurs when the specified field name does not exist in the PDF document. Here are some steps you can take to troubleshoot and resolve this issue:

  1. Verify Field Name: Ensure that the field name you are using in the GetFieldFacade method matches exactly with the field name defined in the PDF. Field names are case-sensitive, so any mismatch will lead to an error.

  2. Check PDF Structure: Open the PDF document and confirm that the field you are trying to access actually exists. You can use PDF editing tools to inspect the fields in the document.

  3. Sample Code: Here is a sample code snippet that demonstrates how to correctly retrieve a form field facade:

    using System;
    using Aspose.Pdf;
    using Aspose.Pdf.Facades;
    
    namespace Aspose.Pdf.Examples.CSharp.AsposePDFFacades.Forms
    {
        public class GetFormFieldValue
        {
            public static void Run()
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Forms();
    
                // Create Form Object
                Aspose.Pdf.Facades.Form pdfForm = new Aspose.Pdf.Facades.Form();
    
                // Open Document
                pdfForm.BindPdf(dataDir + "FormField.pdf");
    
                // Ensure the field name is correct
                string fieldName = "textfield"; // Replace with your actual field name
                FormFieldFacade fieldFacade = pdfForm.GetFieldFacade(fieldName);
    
                // Check if fieldFacade is null
                if (fieldFacade != null)
                {
                    // Get facade values
                    Console.WriteLine("Alignment : {0} ", fieldFacade.Alignment);
                    // Additional properties can be accessed similarly
                }
                else
                {
                    Console.WriteLine("Field not found: " + fieldName);
                }
            }
        }
    }
    
  4. Debugging: Set breakpoints in your code to inspect the values and flow. This will help you identify if the field is being retrieved correctly or if it is returning null.

By following these steps, you should be able to resolve the “Index out of range” error and successfully access the field facade. If the problem persists, consider checking the documentation or seeking further assistance on the forum.

Sources:
[1]: GetFormFieldValue.cs
[2]: GetFieldValue.cs

The field names are coming from:
foreach (var field in _document.Form.Fields)
var name = field.FullName;
var facade = pdfForm.GetFieldFacade(name);

So if we are using the full name provided by the document form fields, I don’t see how the names could be incorrect. I also verified the names in the PDF with the names it is trying to open.
Please Advise.

1 Like

Aspose.FieldIssues.zip (606.8 KB)

I was able to simplify my example.

Please advise

@gmitchell.ipipeline

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-58726

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.