[poppler] annotations survive in saveas copy AFTER removing them

Pierre-Luc Samuel Pierre-Luc.Samuel at ticketmaster.com
Fri Jul 14 16:42:49 UTC 2017


When you get to the second half of the list, getAnnot(x) probably fails 
because you don't have as many items in the list. You should either 
traverse the annotation list in reverse order (from n_annots to 0), or 
always remove annotation 0 in your "for" loop.

Pierre-Luc


On 17-07-14 11:35 AM, Jannick wrote:
>
> Dear All,
>
> my code snip below suggests that ‘a.pdf’ is copied to ‘b.pdf’ AFTER
>
> removing all annotations of a.pdf. However, b.pdf still contains all
>
> annotations seen in a.pdf.
>
> Am I missing something obvious here?
>
> Thanks,
>
> J.
>
> // main.cpp:
>
> #include <stdio.h>
>
> #include <stdlib.h>
>
> #include <PDFDoc.h>
>
> #include <GlobalParams.h>
>
> int main(int argc, char** argv)
>
> {
>
>     const char* f_in = "test_in.pdf";
>
>     const char* f_out= "test_out.pdf";
>
>     GooString gf_in(f_in);
>
>     GooString gf_out(f_out);
>
>     globalParams = new GlobalParams();
>
>     PDFDoc * doc = new PDFDoc(&gf_in);
>
>     if ( doc->isOk() )
>
>     {
>
>         int i_pages = doc->getNumPages();
>
>         for ( int i_page = 1; i_page <= i_pages; i_page++ )
>
>         {
>
>             Page * page = doc->getPage(i_page);
>
>             if( page )
>
>             {
>
>                 Annots * annots = page->getAnnots();
>
>                 int n_annots = annots->getNumAnnots();
>
>                 for ( int i_annot = 0; i_annot < n_annots ; i_annot++ )
>
> annots->removeAnnot(annots->getAnnot(i_annot));
>
>             }
>
>         }
>
> doc->saveAs(&gf_out,writeForceRewrite);
>
>         delete doc;
>
>     }
>
>     else
>
>     {
>
>         fprintf(stderr, "error when opening '%s'\n", f_in);
>
>     }
>
>     delete globalParams;
>
>     return 0;
>
> }
>
>
>
> _______________________________________________
> poppler mailing list
> poppler at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/poppler

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/poppler/attachments/20170714/5afafc0b/attachment-0001.html>


More information about the poppler mailing list