We have an application that appends text to PDF documents. Most of the time, everything works as expected.
For some PDF files, however, we have found that the Aspose.Pdf.Text.TextBuilder constructor throws a NullReferenceException.
I checked the PDF and it does not have any errors ( according to this tool PDF Tools Online - Repair PDF )
Attached is one of the PDFs that we cannot process.
Here is some sample code to reproduce the exception:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AsposePDFTest
{
class Program
{
static void Main(string[] args)
{
var pdfDocument = new Aspose.Pdf.Document(“Test.pdf”);
var page = pdfDocument.Pages[pdfDocument.Pages.Count];
var textBuilder = new Aspose.Pdf.Text.TextBuilder(page); // new TextBuilder(…) throws NullReferenceException
///
/// obfuscated stack trace
///
/*
System.NullReferenceException: Object reference not set to an instance of an object.
at ..(Operator )
at ..Parse()
at ..(BaseOperatorCollection , Resources , Page )
at ..(BaseOperatorCollection , Resources )
at ..()
at .…ctor(Page , TextSearchOptions , Resources , BaseOperatorCollection , Boolean )
at .…ctor(Page , TextSearchOptions , Resources , BaseOperatorCollection )
at .…ctor(Page , BaseOperatorCollection )
at Aspose.Pdf.Text.TextBuilder…ctor(Page page)
at AsposePDFTest.Program.Main(String[] args) in c:\Users\RobertH\Documents\Visual Studio 2012\Projects\AsposePDFTest\AsposePDFTest\Program.cs:line 17
*/
}
}
}