How Preview mangles annotations

A few years ago, Apple decided to completely rewrite its support for PDFs in PDFKit and Quartz2D. The new version broke a lot of existing code, and developers were forced to work around those bugs. Among the apps which had to do this was Apple’s own Preview. One obvious result is that Preview acquired its own bugs in handling PDFs, and hasn’t really recovered yet.

previewann01

Preview isn’t, of course, a ‘serious’ PDF editor. But many use it to read PDFs and to add annotations to them, which aren’t particularly demanding requirements. Even now in Catalina, Preview version 11.0 remains a mess, and has some upsetting bugs.

Take its tools to Annotate a document. Open a copy of a regular PDF in Preview, and use the Highlight Text command in Annotations to highlight several sections of text. Save that document, open it again and chances are that Preview has forgotten the last of those highlighted sections. That is until you select the last highlighted text, when it suddenly remembers it again, as do all third-party apps. This appears to be because the final highlighting is tacked onto the end of the PDF code, where Preview seems to forget it.

previewann02

Select a section of text and highlight it. Select something else, then select that highlighted section again. Click on the highlight tool (not the popup to the right of the tool itself) in the toolbar, and sometimes that applies a different highlight colour (which isn’t even selected in the popup), other times it will remove the highlighting altogether. Select the unhighlighted text again, and sometimes the highlighting reappears spontaneously; if the highlighting is still there, that can also force it to vanish again.

Furthermore Preview won’t let you close a document, even when it still indicates that it hasn’t been saved, without saving it silently for you. This leads to the absurd situation that when you do save a document with highlights, it often forgets the last of those, but when you don’t save the document, it seems to save it even if you didn’t want it to.

One of the problems with Preview’s annotations becomes apparent when you browse the source of a PDF which it has annotated, for example using my free app Podofyllin. Each individual annotation is added as another trailer to the end of the source, and when any are removed from the document they don’t get purged in any file clean-up. A single paragraph with two highlighted sections and two underlined ended up with 25 trailers containing the entire historical record of its previous annotations, which it seemed unable to forget.

previewann05

These are only consolidated into a flattened PDF when rendered by the Quartz2D engine, something which Preview doesn’t reflect in its PDF until you Export as PDF. Even using Save As won’t flatten the PDF. If you want to make Preview’s annotations more robust and reliable, you thus have to Export as PDF to create a cleaned-up version of the document, which inconveniently also strips all previous versions from that document too.

If you want to annotate PDF documents, I recommend that you look at PDF Expert and PDFpen (Pro), both available from the App Store. They’re fine native Mac apps which are far better and create fine PDF source. If you really can’t afford to pay for good quality software, then there’s always Adobe Acrobat Reader, if you happen to like its Martian human interface.

Thanks to Hunter who reminded me it was time to bend my mind with Preview again.