<div dir="ltr"><div><div><div><div>Hello,<br><br></div>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 (<<a href="https://www.w3.org/TR/annotation-model/">https://www.w3.org/TR/annotation-model/</a>>). So far, I've been successful in extracting Text Markup annotations and Text annotations.<br><br></div>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.<br><br></div></div><div></div><div>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.<br><br></div><div>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:<br><br>char* getStampAsPNG(Annot *annot) {<br></div><div>    char* pngBytes;<br></div><div><br>    PDFDoc *doc = annot->getDoc();<br>    int pageNum = annot->getPageNum();<br>    Page *page = doc->getPage(pageNum);<br><br><div>    CairoOutputDev *cairoOut = new CairoOutputDev();<br><br></div>    // ...Cairo configuration...<br><br>    Gfx *gfx = page->createGfx(<br>            cairoOut, resolution, resolution, 0,<br>            gTrue, gFalse,<br>            -1, -1, -1, -1,<br>            gFalse, NULL, NULL<br>     );<br><br>    annot->draw(gfx, gFalse);<br><br></div><div>    // ...write Cairo context as PNG, crop, and store bytes as pngBytes...<br></div><div><br>    delete cairoOut;<br><br></div><div>    return pngBytes;<br></div><div>}<br><br></div><div>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.<br><br></div><div>Thank you,<br></div><div>Patrick<br></div></div>