smalot/pdfparser — pull request #35 by calguy1000 (2014-04-29 17:10:25+00:00)
Title: Significant performance and memory improvement in cleanContent

I encountered a problem with parsing an arcGis generated PDF File that contained one page and numerous images, but no text (per say). the cleanContent routine would take minutes to do it's task and timeout.

Numerous tests indicated that
a: preg_match_all with PREG_OFFSET_CAPTURE would not always return an array of 2 elements (so the offset was sometimes not returned)... which would result in the corruption of the beginning of $content instead of the cleaning of the regex.
b: the foreach loop and substr_replace were extremely slow and memory intensive.
c: using preg_replace_callback with a simple closure was extremely more optimal (down to ~2 seconds from ~166 seconds) and significantly less RAM.

Please check my code.