Flattening fields on attached PDF causes a failure

When using the code below to flatten fields in the attached PDF, an error is raised. It seems to be a problem if there is a period in a field name.


private void FlattenFormFields()
{
var pdf = new Document(@“d:\Aspose\f1040_elmer_orig.pdf”);
//var pdf = new Document(@“d:\Aspose\Fields1-more.pdf”);
List fields = new List();
foreach (Field field in pdf.Form)
{
if (field != null)
{
CollectFields(field, fields);
}
}
foreach (var field in fields)
{
field.Flatten();
}

pdf.Save(@“d:\Aspose\Output.pdf”);
pdf.Dispose();
}

private void CollectFields(Field field, List fields)
{
if (fields != null)
{
if (field.Count > 0)
{
foreach (var subF in field)
{
var subField = subF as Field;
if (subField != null)
{
CollectFields(subField, fields);
}
}
}
fields.Add(field);
}
}

Hi Stacey,

Thanks for using our API’s.

I have tested the scenario and I am able to reproduce the same problem. For the sake of correction, I have logged it in our issue tracking system as PDFNEWNET-38785. We will investigate this issue in details and will keep you updated on the status of a correction

We apologize for your inconvenience.

Checking if there is any status on bug PDFNEWNET-38785.


Thank you

Hi Kim,


Thanks for your patience.

I am afraid the issue reported earlier is pending for review as the team has been busy fixing other previously reported issues. However your concerns have been shared with product team and as soon as we have some definite updates regarding its resolution, we will let you know.

Please be patient and spare us little time.

Hi Kim.

Thanks for your patience.
We have further investigated the earlier reported issue and have observed that you are trying to flatten the “group” field. In order to get the desired output, please modify the CollectField() method in the following manner.

Please try using the latest release of Aspose.Pdf for .NET 11.8.0. If you still face the same problem or have any further queries, please feel free to contact.

[C#]

private void CollectFields(Field field, List<Field> fields)
{
    if (fields != null)
    {
        if (field.Count > 0)
        {
            foreach (var subF in field)
            {
                var subField = subF as Field;
                if (subField != null)
                {
                    CollectFields(subField, fields);
                }
            }
        }
        else
        {
            fields.Add(field);
        }
    }
}

Thank you. This did the trick!

Hi Kim,


Thanks for the acknowledgement.

We are glad to hear that your problem is resolved. Please continue using our API’s and in the event of any further query, please feel to contact.