I have an XFA form that I am able to successfully fill out and save using PdfLoadedXfaDocument. However, when I try to flatten it using document.Flatten = true, a null reference exception occurs. I believe this is because the form contains a "Reset" button as the error message occurs when attempting to draw a button. The actual error message is due to a font not being present as a parameter to the DrawButton function. But my code is not using DrawButton, that is being called internally when Flatten is invoked. See below for relevant error message. Is there a solution or work around to this?
System.ArgumentNullException: Value cannot be null.
Parameter name: font
at Syncfusion.Pdf.Graphics.FieldPainter.DrawButton(PdfGraphics g, PaintParams paintParams, String text, PdfFont font, PdfStringFormat format)
I am able to fill the form, no problem. Its is only flattening that has the issue.
The form is not dynamic in the sense of content reflow, but there is a scripted field, a "Clear Data" button, which I suspect is causing the trouble. The error message refers to a missing font when DrawButton is called. See OP for error message. There is only one button on the form, the Clear Data (reset) button.
Is there any work around to this, perhaps a way of providing the font or a way of removing the button before calling Flatten? I did see a very old forum post (2007) that hinted at providing a font, but the syntax and methods have changed since the post. Is there some way of doing the following with the current API?
f.FlatteningFont = doc1.Fonts.Add(new Font("Arial",12),true);
I have attached the form in question. I have no control over the form design as it is a government form.
Thanks
Hi Louise,
We have support to flatten basic level Xfa documents only. And also, the provided PDF document contains scripted fields, where our PDF library doesn’t have this support. We do not have support for filling and flattening dynamic and scripted fields. We do not have any plans to implement this feature due to XFA has been deprecated in PDF 2.0.
However, you can use the normal Pdf flattening method for this document. Please refer the below code snippet,
|
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(@"../../t4a-fill-21e.pdf");
PdfLoadedForm loadedForm = loadedDocument.Form;
loadedForm.Flatten = true;
loadedDocument.Save("output.pdf");
loadedDocument.Close(); |
Please let us know if you need any further assistance with this.
Regards,
Ravikumar.