Hallo dear podofo users,

I recently wrote some podofo code to remove signature fields. I inspected
the pdf with podofobrowser and removed all objects and references
step-by-step, that worked nice.
But when I thought the removal is complete, I recognized that the AcroForm
Fields-Array still holds an element, which is null.

So I still need to remove the PdfArray element. The PdfArray has an erase
function, which takes a single iterator or a range. For my use case, there
might me multiple elements to be erased, not necessarily grouped up
together, so no range possible, I've got to erase the elements one-by-one.

Here's my solution so far:

typedef std::list<PdfArray::iterator> PdfArrayIteratorList;
PdfArrayIteratorList elems_to_delete;

PdfArray::iterator it = pFieldsArray->begin(), end = pFieldsArray->end();
for ( ; it != end; ++it )
{
    [..] // omitted, checks if field is of type '/Sig' and removes dicts,
objects and references

    // Save array element for subsequent deletion
    elems_to_delete.push_back( it );
}

// Remove all null array entries
PdfArrayIteratorList::const_reverse_iterator del_it =
elems_to_delete.rbegin(), del_it_end = elems_to_delete.rend();
for ( ; del_it != del_it_end; ++del_it )
{
    pFieldsArray->erase( *del_it ); // Is this safe to do??
}

Erasing during an iteration is likely unsafe, since it could invalidate my
iterators.
So there's no erase in the first iteration, all iterators in
elems_to_delete should still be valid.
In the second iteration, I revers-iterate through elems_to_delete and call
erase on any saved iterator.

I use revers iteration, because I don't know how PdfArray is implemented.
It shouldn't be necessary if it's a linked-list or tree-map, that shouldn't
invalidate my iterators.
But if it's really some sort of array, I would expect some shifting after
an erase. The shifting shouldn't affect my (remaining) iterators when I'm
revers iterating.
But that's all just guessing.

So my question is, what is the right, safe way to erase multiple elements
fron a PdfArray? Is my solution ok so far or are there some pitfalls I
overlooked?


Regards,
F.E.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to