Using poppler to extract annotations. g_free() / get_color() issue
<p>I borrowed this python code <a href="http://stackoverflow.com/questions/1106098/parse-annotations-from-a-pdf">here</a> (first answer by enno groper) to automate the extraction of annotations from pdfs. </p>

<p>I want to make some modifications to the code. Trying to fetch the color of annotations with <code>annot_mapping.annot.get_color()</code> I ran into the first issue. What the command returns is objects like this one <code>&lt;PopplerColor at 0x1a85180&gt;</code>, rather than rgb values (<a href="https://people.freedesktop.org/~ajohnson/docs/poppler-glib/poppler-PopplerColor.html#PopplerColor" rel="nofollow">promised here</a>). </p>

<p>According to <a href="https://people.freedesktop.org/~ajohnson/docs/poppler-glib/PopplerAnnot.html#poppler-annot-get-color" rel="nofollow">poppler docs</a> <code>poppler_annot_get_color()</code> returns "a new allocated PopplerColor with the color values of poppler_annot , or NULL. It must be freed with g_free() when done".</p>

<p>Is this correct and if yes, how do I achieve this in python?</p>

<p><code>annot_mapping.annot.get_color()</code> gives you a PopplerColor, which is a structure with three members (of type guint16): red, green, and blue. For example:</p>

<pre><code>PopplerColor *color = poppler_annot_get_color (annot);
g_printf ("%d\n", color-&gt;red);
</code></pre>

<p>gives you the red value of your annotation <code>annot</code>, the gb values can be obtained similarly.</p>

<p>In python this is achieved through <code>annot_mapping.annot.get_color().red</code>, assuming you have <code>import poppler</code></p>

python pdf annotations poppler