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)