[poppler] Annotation creation using Poppler

Fabio D'Urso fabiodurso at hotmail.it
Fri May 18 08:03:28 PDT 2012


On Friday, May 18, 2012 03:34:53 PM Francesco Gabbanini wrote:
> I noticed that version 0.20 of Poppler has introduced the possibility of
> adding, modifying and removing annotations from PDF documents. These
> features seem to be available through the qt4 interface library as well.
Correct. Note that only a subset of what we promise to do is implemented 
(setters for some properties, notably timestamps and popup window, are noops).

> I have read the qt4 interface documentation and I found that annotation
> creation seems to be possible by calling the static method
> Poppler::AnnotationUtils::createAnnotation(const QDomElement
> &annElement), which returns a pointer to an Annotation.
It's one of the two possible ways. The other one is to use the constructor of 
the annotation type you want to create (eg new InkAnnotation) and use setters 
to set the properties.

> I was wondering what is that QDomElement & that has to be given as an
> input to the method.
It's a undocumented format to describe the annotations. You can some get 
examples calling AnnotationUtils::storeAnnotation on existing annotations.
If you have Okular installed, it's also the same format Okular uses to store 
user-created annotations internally (in ~/.kde/share/apps/okular/docdata/).

> Is there some documentation around describing how to work with
> annotations using the qt4 interface?
> Or maybe, does anybody have a simple example on how to create
> annotations in a PDF using the qt4 interface?
No full examples yet. In general, it goes like this:
 Document* document = Document::load(inputfilename);
 Page* pdfPage = document->page(pagenum); // 0-based
 InkAnnotation *ann = new InkAnnotation();
 // Set its properties here ...
 pdfPage->addAnnotation(ann);
 // ... or here (they both work)
 PDFConverter *conv = document->pdfConverter();
 conv->setOutputFileName(outputfilename);
 conv->setPDFOptions(conv->pdfOptions() | PDFConverter::WithChanges);
 conv->convert();

Supported annotation types are: Text, Line, Geom, Ink, Stamp, Highlight.
Note that StampAnnotations are stored to file, but they're not rendered by 
poppler at the moment.

*IMPORTANT*:
Oops! I forgot to make TextAnnotation ctor public. I'm attaching a patch.

Fabio
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-qt4-Make-TextAnnotation-ctor-public.patch
Type: text/x-patch
Size: 1136 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/poppler/attachments/20120518/d4016538/attachment.bin>


More information about the poppler mailing list