[poppler] Rendering individual annotations
Patrick Golden
ptgolden0 at gmail.com
Tue Apr 18 19:43:31 UTC 2017
Hello,
I am in the process of writing a library that extracts annotations from PDF
documents and expresses them in RDF with the Web Annotation Data Model (<
https://www.w3.org/TR/annotation-model/>). So far, I've been successful in
extracting Text Markup annotations and Text annotations.
One thing I am having trouble with is extracting individual stamp
annotations. Ideally, I would like to get PNG images, with transparency,
for each individual annotation, without any other content.
One way this might be possible is to use pdftocairo to convert the page to
a png, using the -transp flag to make it transparent, and the -x/-y/-W/-H
flags to crop only the area containing the stamp. The downside, however is
that this would require a shell call and PDF reparsing for each annotation.
To avoid that, it could be possible to use `poppler_page_render` to render
a single page to a Cairo context, clip that context, and render it to PNG.
The problem with this approach (as well as using pdftocairo) is that if any
other object is in the rectangle of the annotation, it will show up in the
PNG as well.
What I really want to do is *only* draw one single object, rather than all
the objects on an entire page. Something like this (dummy) code:
char* getStampAsPNG(Annot *annot) {
char* pngBytes;
PDFDoc *doc = annot->getDoc();
int pageNum = annot->getPageNum();
Page *page = doc->getPage(pageNum);
CairoOutputDev *cairoOut = new CairoOutputDev();
// ...Cairo configuration...
Gfx *gfx = page->createGfx(
cairoOut, resolution, resolution, 0,
gTrue, gFalse,
-1, -1, -1, -1,
gFalse, NULL, NULL
);
annot->draw(gfx, gFalse);
// ...write Cairo context as PNG, crop, and store bytes as pngBytes...
delete cairoOut;
return pngBytes;
}
Obviously this is not part of poppler's public API, but I think this
expresses what I'm looking to do. Am I missing some way that this might be
possible given the current API? If it seems useful, I would be happy to
contribute.
Thank you,
Patrick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/poppler/attachments/20170418/2f25c29c/attachment.html>
More information about the poppler
mailing list