I have the strangest problem!
I have this simple PDf file (for example):
4625633.pdf (33.4 KB)
When trying to run the code below in RELEASE mode I get this error:
System.NullReferenceException: Object reference not set to an instance of an object.
at #=zq3aZBvkdHjxXrbtpuLj3yA0Ym2ayOkCSxosnhtIMopDjv3nN8IN2ryo=.#=zFQaYzcw=(SelectFont #=zi3rmTaw=)
at #=zq3aZBvkdHjxXrbtpuLj3yA0Ym2ayOkCSxosnhtIMopDjv3nN8IN2ryo=.#=zNBaolN0=(Page #=ziIdMjzs=)
at #=z9wHlJhWp5unhutIFsTPjgRbqNLUsnwSIsu3zHYxXYf3ACs1UtXN1vOZRucbr.#=zzj4MaqakBuxG(BaseOperatorCollection #=zCxXzFe8=, Resources #=zP1naPC0=, Page #=ziIdMjzs=, Rectangle #=z5UfMonoKXnpw)
at #=z9wHlJhWp5unhutIFsTPjgRbqNLUsnwSIsu3zHYxXYf3ACs1UtXN1vOZRucbr.#=zzj4MaqakBuxG(BaseOperatorCollection #=zCxXzFe8=, Resources #=zP1naPC0=, Rectangle #=z5UfMonoKXnpw)
at #=z9wHlJhWp5unhutIFsTPjgRbqNLUsnwSIsu3zHYxXYf3ACs1UtXN1vOZRucbr.#=zx_HoY9w=(Boolean #=zhF4j8loTVfu6)
at #=z9wHlJhWp5unhutIFsTPjgRbqNLUsnwSIsu3zHYxXYf3ACs1UtXN1vOZRucbr..ctor(Page #=ziIdMjzs=, TextSearchOptions #=zZc7Ti8_P_2rm, Boolean #=zrHXOTndZTTL7)
at Aspose.Pdf.Text.TextAbsorber.Visit(Page page)
at Odcanit.Platinum.ContentIndexer.PDF.ContentEnginePDF.ExtractTextFromFile(String filePath)
When running the same code on the same file in DEBUG mode it works perfectly!
Here is the code:
public string ExtractTextFromFile(string filePath)
{
const int MAX_PAGES_EACH_SCAN = 100;
StringBuilder documentText = new StringBuilder();
int totalPages = -1;
int scannedPages = 0;
while (totalPages == -1 || scannedPages < totalPages)
{
//open document
using (Document pdfDocument = new Document(filePath))
{
try
{
if (totalPages == -1) totalPages = pdfDocument.Pages.Count;
//create TextAbsorber object to extract text
TextAbsorber textAbsorber = new TextAbsorber { ExtractionOptions = new TextExtractionOptions(TextExtractionOptions.TextFormattingMode.MemorySaving) };
int currentScanCount = 0;
for (int p = scannedPages + 1; p <= Math.Min(totalPages, scannedPages + MAX_PAGES_EACH_SCAN); p++)
{
// get the extracted text
pdfDocument.Pages[p].Accept(textAbsorber);
currentScanCount++;
}
// Append the text to the buffer
documentText.Append(textAbsorber.Text);
scannedPages += currentScanCount;
}
finally
{
pdfDocument.FreeMemory();
}
}
}
return documentText.ToString();
}