|Xournal PDF embedding wrapper|
|Thursday, 28 January 2010 20:58|
Xournal is a great notebook application to be used on Tablet PCs. It allows for annotation of PDF documents, with the drawing/writing exported directly to the PDF. While there is vector-drawing on top, the underlying PDF is not changed (making use of PDFs updating mechanism), giving rise to a rather high quality result.
Sometimes it turns out to be inconvenient that one ends up with three files — the original PDF, the Xournal file, and the annotated PDF. Because the annotations are just stored as an update, the original PDF can always be recovered by removing the most recent update. Also, PDF allows for embedding files within the document. So in principle, a single file can be sufficient: it appears to be the fully annotated version as exported by Xournal to any PDF viewer. Additionally, the Xournal file is included which allows for editing those annotations after removing the Xournal's PDF attachments.
By making a little script out of this, annotating a PDF (and also editing an already annotated one) is as easy as
and only a single file has to be kept.
The script makes use of PDF::API2 along with PDF:API2::Names. By giving it a non-existent file name, an empty Xournal file is generated in contrast to PDF annotation. Passing an existent Xournal filename will start Xournal and embed the source in the resulting PDF.
What might be most interesting is the code to append some file attachment to a PDF: The Root-object is cloned and the name-tree of embedded files extended by an entry describing the Xournal file and also containing its encoded content.