To check the latest hotfix, we did a run on all pdf files in out system. In the last 3 moths, 155 documents were added to our system which Spire.PDF cannot handle properly. The errors are
- Invalid/Unknown/Unsupported format Unsupported compressor (JPXDecode)
- Index was outside the bounds of the array
- Object reference not set to an instance of an object
- Signature 'Signature1' failed to verified
- StackOverflowException
- Unexpected token
- Value cannot be null
I created a small test tool to test some of the documents:
- Code: Select all
static void Main(string[] args)
{
string[] folders = Directory.GetDirectories(@"C:\DMSAnalyse\");
foreach (string folder in folders)
{
if (!folder.EndsWith(@"InfiniteLoop") &&
!folder.EndsWith(@"StackOverflow"))
{
string[] files = Directory.GetFiles(folder, "*.pdf");
TestMinimal(files);
}
}
Console.WriteLine("Done. Press a key to continue");
Console.ReadKey();
// Method below causes a StackOverflowException in SaveAsImage
string[] files1 = Directory.GetFiles(@"C:\DMSAnalyse\StackOverflow", "*.pdf");
TestMinimal(files1);
////Metchod below causes an infinite loop in SaveAsImage
//string[] files2 = Directory.GetFiles(@"C:\DMSAnalyse\InfiniteLoop\", "*.pdf");
//TestMinimal(files2);
}
private static void TestMinimal(string[] files)
{
foreach (string file in files)
{
try
{
// Constructor crashes on some files (Unexpected token)
using (PdfDocument doc = new PdfDocument(file))
using (PdfDocument mergedPDF = new PdfDocument(PdfConformanceLevel.Pdf_A1B))
{
// Conformance property throws NullReference on some files
PdfConformanceLevel level = doc.Conformance;
mergedPDF.InsertPageRange(doc, 0, doc.Pages.Count - 1);
using (MemoryStream pdfStream = new MemoryStream())
{
// SaveToStream causes invalid format in some pdf's
mergedPDF.SaveToStream(pdfStream);
}
// SaveAsImage causes several errors, sometimes stack overflow, sometimes index out of bounds etc.
using (Image bitmapTemp = doc.SaveAsImage(0, 72, 72))
{
// do nothing
}
}
}
catch (Exception ex)
{
Console.WriteLine(file + ": " + ex.ToString());
}
}
}
Due to privacy issues, I cannot share the documents on a public forum, our client will send the documents in an e-mail.
Please note that one particular document causes the doc.SaveAsImage(0, 72, 72) call to go in an infinite loop, however I cannot send you that document because it's a scan of a Dutch passport. I hope you can discover the cause by code inspection.
Kind regards,
Sikke Kooistra