Hi,
I have ran into NullReferenceException issue while trying to use the ExtractText Function.
I have 2 scenarios, 1 which is working and 1 which is not.
For the one that is working, I used a PDF that is generated from IText.
For the one that is hitting the NullReferenceException, the PDF used was generated from PrinceXML.
The code used was the following:
Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument();
doc.LoadFromFile(@"C:\Users\TestUser\Desktop\TestFolder\Admin_Note.pdf");
int pageCount = doc.Pages.Count; //This is to check if document really contains same page as my PDF document
//Extract text from page
for (int i = 0; i < pageCount; i++)
{
if (i == 0)
{
//partialText = doc.Pages[i].ExtractText(); //This doesnt works too
partialText = doc.Pages[i].ExtractText(new Rectangle(0, 0, 300, 300)); //I changed the values for the Rectangle constructor but it doesnt work too. An exception of type
//'System.NullReferenceException' occurred in Spire.Pdf.dll but was not handled in user code
//Object reference not set to an instance of an object.
StringBuilder sb = new StringBuilder();
sb.AppendLine(partialText);
Debug.WriteLine(sb);
}
StringBuilder content = new StringBuilder();
content.Append(doc.Pages[i].ExtractText());
Debug.WriteLine("Text from page " + (i+1) + ": " + content);
}