[poppler] Annotation creation using Poppler
Francesco Gabbanini
fgabbanini at gmail.com
Thu May 24 08:46:21 PDT 2012
Many thanks for your help Fabio!
I have tryed to work on your example and wrote the following code:
Poppler::LineAnnotation *ia = new
Poppler::LineAnnotation(Poppler::LineAnnotation::StraightLine);
QLinkedList<QPointF> points;
points.push_back(QPointF(50, 50));
points.push_back(QPointF(150, 150));
ia->setLinePoints(points);
Poppler::Annotation::Style style;
style.setColor(QColor(0, 0, 0));
style.setWidth(4.0);
ia->setStyle(style);
Poppler::Page *p = _doc->page(npage);
p->addAnnotation(ia);
Poppler::PDFConverter *conv = _doc->pdfConverter();
conv->setOutputFileName(QString("C:/Users/.../test.pdf"));
conv->setPDFOptions(conv->pdfOptions() |
Poppler::PDFConverter::WithChanges);
conv->convert();
I then tried to open the document with Nitro PDF Professional.
It seems that the annotation is there, because it is displayed by Nitro
PDF when I click on the "Comments" button, but I cannot see it on the
screen (I expected to see it drawn over the document).
I also tried to open the PDF with the Chrome browser's internal viewer,
but the result is the same.
Am I missing something?
Thanks in advance,
Francesco.
On 18/05/2012 17:03, Fabio D'Urso wrote:
> 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
>
>
> _______________________________________________
> poppler mailing list
> poppler at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/poppler
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/poppler/attachments/20120524/392c8058/attachment.htm>
More information about the poppler
mailing list