Code improvements

The scope of this pull request has grown since I first pushed, since I thought it would be too much effort to disentangle each of the different changes and send them as separate pull requests.

The aim for this pull request is to massage the code into a cleaner state without changing any of the logic.

At the moment this mostly means comments, docstrings, renaming of classes, moving code around and introducing an abstract base class for PDFDocument and PDFPage.

I suggest reviewing the patches individually.

Criticism welcome. I won't be hurt if you don't like something for any reasons - there are lots of possible right answers and I picked the ones which made the most sense to me at a glance.