[poppler] Rendering individual annotations

Albert Astals Cid aacid at kde.org
Wed Apr 19 13:54:40 UTC 2017


El dimarts, 18 d’abril de 2017, a les 15:43:31 CEST, Patrick Golden va 
escriure:
> 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? 

I don't think you can do what you want, noone seems to have had your need.

> If it seems useful, I would be happy to contribute.

Patches welcome :)

Cheers,
  Albert

> 
> Thank you,
> Patrick




More information about the poppler mailing list