Hello,
I am using Aspose.PDF for .NET version 24.12.0. I am trying to convert an XFA Dynamic PDF to a regular non-form PDF. I start by converting the document from Dynamic XFA to standard AcroForm and then I flatten it. However, the resulting file is missing several of the form entries, shrinking the page count from 8 to 5 in the process. In particular, several of the rows of data are disappearing. How do I properly flatten a Dynamic XFA file while retaining all of the form entries?
I have attached sample input and output files. Here is the code I am using:
Aspose.Pdf.License licensePdf = new Aspose.Pdf.License();
licensePdf.SetLicense("Aspose.Total.lic");
string importFilePath = "Input.pdf";
string exportFilePath = "Output.pdf";
if (File.Exists(exportFilePath))
{
File.Delete(exportFilePath);
}
using (var pdfDocument = new Aspose.Pdf.Document(importFilePath))
{
pdfDocument.Form.Type = Aspose.Pdf.Forms.FormType.Standard;
pdfDocument.Flatten();
pdfDocument.Save(exportFilePath);
}
Thank you for your help!
Input.pdf (1.3 MB)
Output.pdf (1.3 MB)
@jstewbhai
To properly flatten a Dynamic XFA PDF while retaining all form entries, you need to ensure that the conversion from Dynamic XFA to Standard AcroForm is done correctly before flattening the document. The issue you are experiencing, where several rows of data are disappearing and the page count is reduced, may be related to how the form fields are being handled during the conversion process.
Here’s a revised approach to your code that includes a check for the form fields after conversion, which may help in retaining all entries:
Aspose.Pdf.License licensePdf = new Aspose.Pdf.License();
licensePdf.SetLicense("Aspose.Total.lic");
string importFilePath = "Input.pdf";
string exportFilePath = "Output.pdf";
if (File.Exists(exportFilePath))
{
File.Delete(exportFilePath);
}
using (var pdfDocument = new Aspose.Pdf.Document(importFilePath))
{
// Convert to Standard AcroForm
pdfDocument.Form.Type = Aspose.Pdf.Forms.FormType.Standard;
// Check if form fields are present
if (pdfDocument.Form.Fields.Count > 0)
{
// Flatten the document
pdfDocument.Flatten();
}
else
{
Console.WriteLine("No form fields found to flatten.");
}
// Save the resultant PDF
pdfDocument.Save(exportFilePath);
}
Key Points:
- Form Type Conversion: Ensure that the form type is set to Standard AcroForm before flattening.
- Field Check: Before flattening, check if there are any form fields present. This can help you debug if the fields are being lost during the conversion.
- Debugging: If the issue persists, consider examining the input PDF to ensure that all expected data is present and correctly formatted.
If you continue to experience issues, it may be beneficial to review the documentation or examples related to converting Dynamic XFA forms to Standard AcroForms, as they may provide additional insights or methods to handle specific cases.
Sources:
[1]: ConvertDynamicXFAFormToStandardAcroForm.java
I can confirm there are form fields present after the conversion to Standard AcroForm.
@jstewbhai
I’ll investigate this issue and write you back as soon as possible
@jstewbhai
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-59053
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.
Currently, this issue doesn’t seem to have workaround, so I added task for development team to investigate