Convert Dynamic XFA to AcroForm using Aspose.PDF for .NET - problem in output PDF

I have just downloaded Aspose.Pdf for .Net to evaluate for my company the possibility to convert XFA files with dynamic fields to PDF.
I am testing the samples, I executed the “DynamicXFAToAcroForm” sample, but the resulting PDF had the "Please wait… " message saying perhaps I have a wrong version of acrobat, but I have last full version.

I need to be able to add rows in table where there is a “+” button or delete when there is the “-” button. Is it possible to do it with Aspose.pdf ?
thanks !

@frgost

Thank you for contacting support.

Would you please share a sample PDF document containing XFA form so that we may try to reproduce and investigate it in our environment. Moreover, Aspose.PDF for .NET API mimics the behavior of Adobe Acrobat so would you please share a sample PDF file as your expected output for adding or removing rows so that we may investigate further to help you out.

Hi thank you for your answer, as I have not been noticed I posted the same question in a new topic but I don’t find how to cancel it.
So here is the file 2A1.044A_PREFIC_Questionnaire - Original.pdf (1.8 MB)

I need to answer to the customer before this evening so it is fine if you could help :slight_smile:
thanks a lot
regards

@frgost

Thank you for sharing requested data.

Can you please try to flatten the PDF document containing the filled XFA form with below code snippet using Aspose.PDF for .NET 19.2 and then share your kind feedback with us.

Document doc = new Document(dataDir + "2A1.044A_PREFIC_Questionnaire - Original.pdf");
foreach (string fieldName in doc.Form.XFA.FieldNames)
{
    XmlNode template = doc.Form.XFA.GetFieldTemplate(fieldName);
    XmlAttribute access = template.OwnerDocument.CreateAttribute("access");
    access.Value = "readOnly";
    template.Attributes.Append(access);
}
doc.Save(dataDir + "flattenedXFA_19.2.pdf");

Thank very much for your answer.

I tried your code (I had to add ‘using System.Xml’)

but unfortunately when executing, it ends with a System.NullReference Exception on the line :
XmlAttribute access = template.OwnerDocument.CreateAttribute(“access”)

@frgost

You may try to flatten a filled acro form or surround suggested code snippet in a try-catch block if you want to process unfilled form, and then share your kind feedback with us.

Document doc = new Document(dataDir + "2A1.044A_PREFIC_Questionnaire - Original.pdf");
foreach (string fieldName in doc.Form.XFA.FieldNames)
{
    try
    {
        XmlNode template = doc.Form.XFA.GetFieldTemplate(fieldName);
        XmlAttribute access = template.OwnerDocument.CreateAttribute("access");
        access.Value = "readOnly";
        template.Attributes.Append(access);
    }
    catch (Exception ex)
    {
        continue;
    }
}
doc.Save(dataDir + "flattenedXFA_19.2.pdf");