Call To XFA Flatten Results In Null Reference Exception

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)


4 Replies

GK Gowthamraj Kumar Syncfusion Team March 1, 2022 11:24 AM UTC

Hi Louise, 

We have tried to reproduce the reported issue with test document on our end, but it is flattening properly. We have attached the sample with test document for your reference, please try the sample with input document on your end and let us know the result. 


Please refer to the below documentation link for more details, 

We suspect that the XFA form fields in your PDF document may contains scripted dynamic fields, where our PDF library doesn’t have this support. At present, we have a support to fill and flattening the static XFA fields and we do not have support for filling and flattening dynamic fields. We do not have any plans to implement this feature due to XFA has been deprecated in PDF 2.0.   
 
If the input document contain static XFA fields and issue occurs, we request you to share the modified sample, input document, exception or error details with replication steps to reproduce the issue on our end. So that, it will helpful for us.

 
Regards, 
Gowthamraj K 



LO Louise March 1, 2022 06:05 PM UTC

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


Attachment: t4afill21e_27ea0053.zip


GK Gowthamraj Kumar Syncfusion Team March 2, 2022 12:18 PM UTC

Hi Louise, 

As we said earlier, the PDF document contains scripted fields, where our PDF library doesn’t have this support. At present, we have a support to fill and flattening the static XFA fields and we do not have support for filling and flattening dynamic fields. We do not have any plans to implement this feature due to XFA has been deprecated in PDF 2.0.    

However, we are analyzing the other possibilities to remove the (Clear data) button before calling document flatten on our end and we will update the further details on March 4th 2022. 

Regards, 
Gowthamraj K 



RB Ravikumar Baladhandapani Syncfusion Team replied to Gowthamraj Kumar March 4, 2022 07:11 PM UTC

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.



Loader.
Up arrow icon