I spent the last few months building a PDF editor. The feature that sounded easiest — change a word, leave everything else alone — turned out to be the one that ate most of the time. Here is what I learned, mostly by getting it wrong.
A PDF does not contain sentences
The first assumption to give up is that a PDF stores text. It stores drawing instructions. A line of text is typically a sequence like this:
BT
/F1 11 Tf







