rschroll/prsannots — Issue #1: Support annotations of highlighted material
Author: rschroll
Created: 2012-02-05 01:40:53+00:00
State: open

prsannots should be able to add annotations to the PDF file from annotations to highlighted passages. It should also transfer highlights without attached annotations. There are two hurdles to overcome: reading the annotations from the ereader and creating PDF annotations. Neither should be insurmountable.

Finding annotations
---------------------------
These annotations are stored in the 'annotation' table of books.db. A quick glance reveals the following columns that might be useful:

markup_type
An integer. 10 means just highlighted, 11 means text, 12 means drawing.

marked_text
The marked text, with spaces removed. May be useful in helping find the text on the page.

page
The page as a float, where 'int(page)' gives the zero-indexed page.

mime_type
Either 'application/x-sony-notepad-text' or 'application/x-sony-notepad-svg', or NULL

file_path
What you think.

mark
Blobs that apparently show the extent of the highlighting. Actually text of the form '#pdfloc(A,B,C,D,E,F,G,H)'. A is a four-digit hex number, possibly connected to the file. B is the page. C and D have something to do with the vertical and horizontal positions, respectively. F is 0 and H is 1 in the few examples I've looked at. E and G are usually 0, but not always.

mark_end

Creating PDF Annotations
-----------------------------------
For whatever reason, open source libraries don't seem to want to deal with PDF annotations. Poppler supports [annotations](http://people.freedesktop.org/~ajohnson/docs/poppler-glib/PopplerAnnot.html), but only supports adding annotations to pages since 0.16. The [Python bindings](https://launchpad.net/poppler-python), unfortunately, seem to be stuck at 0.12, with no sign of life. Worse yet, merely creating an annotation in Python results in a seg fault (!). Presumably, there will be a GObject Inspection version eventually, but I don't know when that will be.

There are [bindings to the Qt4 version of Poppler](http://code.google.com/p/python-poppler-qt4/), but I haven't gotten them to compile. They seem to require a bunch of Qt.

With pyPdf, which we're already using, you can see existing annotations. It may be possible to add additional annotations, but it means mucking about in low-level PDF stuff.

[PDF Clown](http://www.stefanochizzolini.it/en/projects/clown/) is a Java/.NET library for PDF manipulation. It supports [highlighting](http://pdfclown.wordpress.com/2011/04/12/waiting-for-pdf-clown-0-1-1-release/), but I don't know about annotations. Perhaps this could be used with IronPython. (Of course, Ubuntu had to go and [remove IronPython](https://bugs.launchpad.net/ubuntu/+source/dlr-languages/+bug/831402) from 11.10, so I can't check this easily.)