An error occurs while flattening PDF document - Aspose.PDF

Hi @aspose.notifier,
i’m facing same issue, below is the error i’m getting while flattening the fields in the PDF. i’ve checked with 24.2 as well, but getting the below error.

[#=zrqioYeoeEV9SrAkxSuXwlVRFoFoRSTIdcnlEp9Lh418zDkwv9Q==] Double #=zF$SzO8Y=() | Error in AsposePdfManager.FlattenAllPdfFields - System.InvalidCastException: Unable to cast object of type ‘#=zCSGqRHoKA8soenH3p5ChG$6imxRc3xUrKg==’ to type ‘#=zNyLJ8QjLERsSFWJ$3mviCYGmc9tNZH6AAA==’.
at #=zrqioYeoeEV9SrAkxSuXwlVRFoFoRSTIdcnlEp9Lh418zDkwv9Q==.#=zF$SzO8Y=()
at Aspose.Pdf.Operators.SelectFont.#=za_2Mies=(#=ztcU$RTg4dbztq6VbK8ZbCHFbaFi070ZE8eHjqW9thJ_g #=z84rCWX4=)
at Aspose.Pdf.Operator…ctor(Int32 #=zVTdo7Mo=, #=ztcU$RTg4dbztq6VbK8ZbCHFbaFi070ZE8eHjqW9thJ_g #=z84rCWX4=)
at Aspose.Pdf.Operators.TextOperator…ctor(Int32 #=zVTdo7Mo=, #=ztcU$RTg4dbztq6VbK8ZbCHFbaFi070ZE8eHjqW9thJ_g #=z84rCWX4=)
at Aspose.Pdf.Operators.TextStateOperator…ctor(Int32 #=zVTdo7Mo=, #=ztcU$RTg4dbztq6VbK8ZbCHFbaFi070ZE8eHjqW9thJ_g #=z84rCWX4=)
at Aspose.Pdf.Operators.SelectFont…ctor(Int32 #=zVTdo7Mo=, #=ztcU$RTg4dbztq6VbK8ZbCHFbaFi070ZE8eHjqW9thJ_g #=z84rCWX4=)
at Aspose.Pdf.Operator.#=zwAmyEXg=(Int32 #=zVTdo7Mo=, #=ztcU$RTg4dbztq6VbK8ZbCHFbaFi070ZE8eHjqW9thJ_g #=z84rCWX4=)
at Aspose.Pdf.Annotations.DefaultAppearance.#=zfW4XeCs=(#=zLu5jpm9jX4Tm8fXTeNLJYyAaSlbMgni8uA== #=zW2qbS5TLh$Utd5_$Bw==)
at Aspose.Pdf.Annotations.DefaultAppearance…ctor(#=zLu5jpm9jX4Tm8fXTeNLJYyAaSlbMgni8uA== #=zW2qbS5TLh$Utd5_$Bw==)
at Aspose.Pdf.Annotations.WidgetAnnotation.get_DefaultAppearance()
at Aspose.Pdf.Forms.TextBoxField.#=zh32E2wKQkToV(#=z6nLsQfU_JaOF #=zcNboDaU=, Annotation #=z8PqDbq0=)
at Aspose.Pdf.Annotations.WidgetAnnotation.#=zxTh7IXA=(Annotation #=z8PqDbq0=)
at Aspose.Pdf.Page.#=zplEfRhs=(Boolean #=z1tFhC$xzvn$fLkumFw==)
at Aspose.Pdf.Document.#=zlW0m4gs=()
at Aspose.Pdf.Document.Flatten(FlattenSettings flattenSettings)
at Aspose.Pdf.Document.Flatten()
at Aspose.Pdf.Facades.Form.FlattenAllFields()

@NPSwaroop

Can you please share your sample PDF document for our reference with the sample code snippet? We will test the scenario in our environment and address it accordingly.

Hi @asad.ali ,
Sorry for getting back to you so late. Attaching the sample file for testing. same file when flattening using aspose 24.2 version also failing.

PFA.

SamplePDF_FlattenningIssue.pdf (1.4 MB)

@NPSwaroop

Can you please share what code snippet are you using to flatten this document? Also, have you tried with 25.5 version?

Hi @asad.ali ,
here is the code we’re using. and we didn’t try with 25.5 version. we’ll try and let you know.

Aspose.Pdf.Facades.Form flattenForm = new Aspose.Pdf.Facades.Form();
flattenForm.BindPdf(pdfFileName);
flattenForm.FlattenAllFields();
flattenForm.Save(flattenFile);

@NPSwaroop

We checked in our environment and did not notice any issues with 25.5 version of the API. Attached is the output PDF document for your kind reference.
SamplePDF_FlattenningIssue_out.pdf (1.4 MB)

Hi @asad.ali , can you check with 24.2 version in your environment, if possible.

@NPSwaroop

We are afraid that we cannot test with 24.2 version of the API because we provide support on the basis of the latest available version of the API. There have been a lot of changes in the API since then and we recommend that you please test with 25.5 version and let us know if you face any issues.