When using the Aspose.Pdf.dll ( version 25.1 and 25.5) , calling the Aspose.Pdf.Facades.Form.ImportFdf method results in error "unable to cast object of type ‘aspose.pdf.annotations.widgetannotation’ to type ‘aspose.pdf.forms.field’ ". Please see the code below:
internal void ImportFdf()
{
FileStream fdfStream = new FileStream(“C:\29.fdf”, FileMode.Open);
string pdfFile = "C:\\29.pdf";
// Get the form from the document
Aspose.Pdf.Facades.Form form = new Aspose.Pdf.Facades.Form(pdfFile);
form.ImportFdf(fdfStream);
fdfStream.Dispose();
}
Attached is a zip file containing two files: 29.pdf, 29.fdf
29.zip (241.5 KB)
@ShazAccessGroup
The error you are encountering, “unable to cast object of type ‘aspose.pdf.annotations.widgetannotation’ to type ‘aspose.pdf.forms.field’,” typically indicates a compatibility issue between the FDF data and the PDF form fields. Here are some steps you can take to troubleshoot and potentially resolve this issue:
-
Check PDF and FDF Compatibility: Ensure that the fields defined in your FDF file correspond correctly to the fields in your PDF form. If there are discrepancies, such as missing fields or mismatched field types, it can lead to casting errors.
-
Update Aspose.PDF Library: Since you are using versions 25.1 and 25.5, consider updating to the latest version of the Aspose.PDF library. Newer versions often include bug fixes and improvements that may resolve your issue.
-
Inspect the FDF File: Open the FDF file in a text editor to verify its structure. Ensure that it correctly references the fields in the PDF. If the FDF file is malformed or contains unexpected data types, it could lead to casting issues.
-
Simplify the FDF Data: If possible, try importing a simpler FDF file with fewer fields to see if the issue persists. This can help isolate whether the problem is with specific fields or the overall structure.
-
Error Handling: Implement error handling in your code to catch exceptions and log detailed error messages. This can provide more insight into what might be going wrong during the import process.
Here is a modified version of your code with basic error handling:
internal void ImportFdf()
{
try
{
using (FileStream fdfStream = new FileStream("C:\\29.fdf", FileMode.Open))
{
string pdfFile = "C:\\29.pdf";
Aspose.Pdf.Facades.Form form = new Aspose.Pdf.Facades.Form(pdfFile);
form.ImportFdf(fdfStream);
}
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
}
This code will help you catch any exceptions that occur during the import process and provide a clearer understanding of the issue.
If the problem persists after trying these suggestions, consider reaching out to Aspose support with detailed information about your PDF and FDF files for further assistance.
The error still occurs after making suggested changes
@ShazAccessGroup
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-59919
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.
@mparker.access
We have taken your concerns into our account and are tagging you in this thread where you can follow up about the issue progress.
Hello Aspose Support Team,
I know that your free support is answered in the order requests are received, and that there is no set time for replies. I am writing to ask if there is any update on my support request. If you need more information from me, please let me know.
Thank you for your help.
Best regards,
Mark
@mparker.access
Sadly, there are no updates at the moment as the ticket was recently logged and it will be prioritized on first come first serve basis. As soon as we have some news about its resolution or ETA, we will share with you in this very forum thread. We will also ask in case we need some information from your side. Please be patient and spare us some time.
We are sorry for the inconvenience.
1 Like
No problem. Thanks for the prompt response.
M