I am trying to evaluate the Spire.PDF package, and I seem to be running into an exception when checking to see if the ImagesInfo property of a valid instance of a PdfPageBase is null. Instead of actually returning null, as expected, it throws a null Reference Exception when the PdfPageBase is from a pdf that is new or in memory. For an existing pdf, however, it works fine and returns either a null value or the data present. Please see the code below for an example.
- Code: Select all
foreach (PdfPageBase page in doc.Pages)
{
if (page != null)
{
try
{
//The following line is where the exception is thrown 100% of the time in a new file even when data is added
if (page.ImagesInfo != null)
{
foreach (PdfImageInfo info in page.ImagesInfo)
{
page.TryCompressImage(info.Index);
}
}
}
catch (Exception ex)
{
//This is because SpirePDF seems to throw an exception when ImagesInfo is null, instead of just returning null.
}
}
}
Any help would be greatly appreciated. Thanks!