System.InvalidCastException error on convert function

We had to remove active contents from pdf like javascript actions, embedded executable files, external content references,events and macros as these can be easily manipulated by users to invoke malware or cross scripting attacks. I didn’t find any specific functions for this in aspose.Pdf while for office files, RemoveMacros() function somewhat capable.

Hence, sanitize these malicious files, we are converting these into PDF/A ie…PDF_A_3A standard using

Aspose.Pdf.Document.Convert function

as this pdf standard does not support these active contents.

This is working fine mostly until we got an System.InvalidCastException error on some of the user uploaded files which is generally edited by a some pdfwriter applications

.I don’t understand why and how to resolve this? Please help me out. We’re using Aspose.Pdf v10.9.

Aspose.Pdf.Document doc = new Aspose.Pdf.Document(fileupload.InputStream);
bool flag = doc.Convert(new MemoryStream(), Aspose.Pdf.PdfFormat.PDF_A_3A, Aspose.Pdf.ConvertErrorAction.Delete);
doc.Save(objFileStream, Aspose.Pdf.SaveFormat.Pdf);

System.InvalidCastException: Unable to cast object of type ‘‡a.’ to type ‘‡a.Œ’.
at —.˜.(Œ , Int32 , Int32 )
at —.˜.(PageCollection )
at —.˜.†()
at —..‹‹()
at —.˜.Process(XmlTextWriter , PdfFormat , Document , Boolean , ConvertErrorAction )
at Aspose.Pdf.Document.Convert(Stream outputLogStream, PdfFormat format, ConvertErrorAction action)

@satyaAspose

Thank you for contacting support.

Please note that support is provided based on latest available version of the API so please upgrade to Aspose.PDF for .NET 19.4 in your environment and then try to Convert PDF file to other Formats. In case you face any issue then share source PDF file with us.