PdfTextExtractor.GetTextFromPage suddenly giving empty string

Viewed 1336

We've been using the iTextSharp libraries for a couple of years now within an SSIS process to read some values out of a set of PDF exam documents. Everything has been running nicely until this week when suddenly we are getting the return of an empty string when calling the PdfTextExtractor.GetTextFromPage method. I'll include the code here:

    // Read the data from the blob column where the PDF exists
    byte[] byteBuffer = Row.FileData.GetBlobData(0, (int)Row.FileData.Length);

    using (var pdfReader = new PdfReader(byteBuffer))
    {

        // Here is the important stuff
        var extractStrategy = new LocationTextExtractionStrategy();

        // This call will extract the page with the proper data on it depending on the exam type
        // 1-page exams = NBOME - need to read first page for exam result data
        // 2-page exams = NBME - need to read second page for exam result data
        // The next two statements utilize this construct.
        var vendor = pdfReader.NumberOfPages == 1 ? "NBOME" : "NBME";

        *** THIS NEXT LINE GIVES THE EMPTY STRING
        var newText = PdfTextExtractor.GetTextFromPage(pdfReader, pdfReader.NumberOfPages == 1 ? 1 : 2, extractStrategy);

        var stringList = newText.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

        var fileParser = FileParseFactory.GetFileParse(stringList, vendor);

        // Populate our output variables
        Row.ParsedExamName = fileParser.GetExamName(stringList);
        Row.DateParsed = DateTime.Now;
        Row.ParsedId = fileParser.GetStudentId(stringList);
        Row.ParsedTestDate = fileParser.GetTestDate(stringList);
        Row.ParsedTestDateString = fileParser.GetTestDateAsString(stringList);
        Row.ParsedName = fileParser.GetStudentName(stringList);
        Row.ParsedTotalScore = fileParser.GetTestScore(stringList);
        Row.ParsedVendor = vendor;
    }

This is not for all PDFs, by the way. To explain more, we are reading in exam files. One of the exam types (NBME) seems to be reading just fine. However, the other type (NBOME) is not. However, prior to this week, the NBOME ones were being read fine.

This leads me to think it is an internal format change of the PDF file itself.

Also, another bit of information is that the actual pdfReader has data - I can get a byte[] array of the data - but the call to get any text is simply giving me empty.

I'm sorry I'm not able to show any exam data or files - that information is sensitive.

Has anybody seen something like this? If so, any possible solutions?

1 Answers
Related