I need to make pre-populated PDF/XFA forms read-only (as in no inputs, such as text, checkboxes, radio buttons etc. can have their values changed).
For regular AcroForms PDFs and static XFA forms, I can accomplish this by calling setFormFlattening(true)
on the PdfStamper instance. For dynamic XFA forms, I have to set an access
attribute of the XDP's field
node to be readOnly
.
The problem is, how do I detect if a form is dynamic XFA? isXfaPresent
doesn't differentiate between static or dynamic XFA forms, so isn't useful.
To add to Bruno's answer and to provide C# example code:
PdfReader reader = new PdfReader(filePath);
XfaForm xfa = new XfaForm(reader);
//Check if PDF file contains Dynamic XFA data
if (xfa != null && xfa.XfaPresent && xfa.Reader.AcroFields.Fields.Keys.Count == 0)
{
MessageBox.Show("This PDF contains Dynamic XFA data.");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With