Particular PDF causes null reference exception to be thrown

On page 1456 of this document, Aspose.PDF 10.1.0 throws a null reference exception. Aspose 9.9.0 runs fine.


using (FileStream fs = new FileStream(this.pdfPath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
if (fs.CanRead)
{
MemoryStream ms = new MemoryStream();
fs.CopyTo(ms);
this.pdfDocument = new Aspose.Pdf.Document(ms, true);
}
}


try{
TextAbsorber textAbsorber = new TextAbsorber
{
ExtractionOptions =
{
FormattingMode = Aspose.Pdf.Text.TextOptions.TextExtractionOptions.TextFormattingMode.Raw
}
};

this.pdfDocument.Pages[1456].Accept(textAbsorber);
textToReturn = textAbsorber.Text;
} catch (Exception ex) {
Logger.LogError(@“PdfOcrDocument.GetTextForPage caught exception and is returning no text: {0}”, ex.ToString());
}


Hi Kent,


Thanks for your inquiry. I have tested the scenario using Apose.Pdf for .NET 10.1.0 4.0 Framework dll and VS2010 over Win 7 64 bit. But I am afraid I am unable to notice the reported exception. Can you please share some more details to replicate the issue? We will appreciate it if you please share a console application to replicate the issue at our end.

We are sorry for the inconvenience caused.

Best Regards,
This program returns an IndexOutOfRange exception. This is not the null reference exception we in get our production code and what I originally reported. Regardless the test document has 1905 pages. The below code is looking at page 1456.




using System;
using System.IO;
using Aspose.Pdf.Text;

namespace AsposeBugReports
{
class Program
{
private const string pdfPath = "D:\\Kevo\\Common\\TestFiles\\AllTypes\\Good_PDF.pdf";
private static Aspose.Pdf.Document pdfDocument;

static void Main(string[] args)
{
using (FileStream fs = new FileStream(pdfPath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
if (fs.CanRead)
{
MemoryStream ms = new MemoryStream();
fs.CopyTo(ms);
pdfDocument = new Aspose.Pdf.Document(ms, true);
}
}

Console.WriteLine(@"Page count of this document: {0}", pdfDocument.Pages.Count);
string textToReturn = "";
try
{
TextAbsorber textAbsorber = new TextAbsorber
{
ExtractionOptions =
{
FormattingMode = Aspose.Pdf.Text.TextOptions.TextExtractionOptions.TextFormattingMode.Raw
}
};

// Page count of PDF is 1905. 1456 is well in that range
pdfDocument.Pages[1456].Accept(textAbsorber);
textToReturn = textAbsorber.Text;
}
catch (Exception ex)
{
Console.Write(@"Caught exception. Aspose.PDF is returning no text: {0}", ex.ToString());
}

Console.Write(textToReturn);
Console.Write("\r\n\r\n\r\n");
Console.WriteLine(@"Press any key to close.");
Console.WriteLine();
Console.ReadKey();
return;
}
}
}

Hi Kent,


Thanks for sharing complete code. I am afraid I am still unable to reproduce reported IndexOutOfRange exception. I am able to access 1456 page and extracts text. Can you please share your environment details to replicate the issue at our end.

We are sorry for the inconvenience caused.

Best Regards,

I am using VS2013 with Update 4 build against .Net 4.5.1 on Windows 7 x64. Aspose.PDF 10.1.0 which is using runtime v4.0.30319.

Note, I forgot to provide a license in the code from my previous post. I believe that omission was the cause for the IndexOutOfRange exception. I am assuming that even though the page count is 1905 there is some limitation getting those pages out of the collection while in evaluation mode.

Once I added reading the a valid license to the code I am back to thorwing a NullRefernceException.

Also note that when I revert back to Aspose.PDF 9.9.0 with this project I get output very similar to what you have posted in your most recent screenshot.

I have modified the source and I am hosting the complete project here.

I have also attached the output I see when I run this program with a valid license.




AA.Engineering:
Note, I forgot to provide a license in the code from my previous post. I believe that omission was the cause for the IndexOutOfRange exception. I am assuming that even though the page count is 1905 there is some limitation getting those pages out of the collection while in evaluation mode.
Hi Kent,

When using the API in trial mode, there is a limitation in terms of number of pages which can be manipulated with API. But even when using the API in trial mode, a proper message stating evaluation mode limitations should be displayed, instead of an exception. However we will also test this scenario and will share our findings.

AA.Engineering:
Once I added reading the a valid license to the code I am back to thorwing a NullRefernceException.

Also note that when I revert back to Aspose.PDF 9.9.0 with this project I get output very similar to what you have posted in your most recent screenshot.

I have modified the source and I am hosting the complete project here.

I have also attached the output I see when I run this program with a valid license.
We are further testing the scenario using updated project and will keep you posted with our findings.

Any progress updates?

Hi Kent,


Thanks for your patience. I have tested the scenario in VS2013 and managed to reproduce the reported exception. We have logged a ticket PDFNEWNET-38351 in our issue tracking system for further investigation and resolution. We will keep you updated about the issue resolution progress.

We are sorry for the inconvenience caused.

Best Regards,