Q: I think I stumbled upon a small issue in NumberTreeIterator...
pdftron::SDF::NumberTreeIterator it = pageinfo_ntree.GetIterator();
while( it.HasNext() ) {
pdftron::Int32 id = it.Key();
pdftron::SDF::Obj obj = it.Value();
new_ntree.Put( id, obj );
it.Next();
}
new_ntree and pageinfo_ntree are both NumberTree objects.
pageinfo_ntree has two items so the body of the while-loop is executed
twice. obj is different for both runs, but id stays the same. Is it
possible that the value of the key doesn't get updated when I call
Next()?
------------
A: We looked into this issue, and it is caused by a minor error in
your code. The key for NumberTreeIterator is SDF::Obj (a number) – so
it not an iteger. The following code generates the correct output:
// Assuming C++ ...
PDFNet::Initialize();
try
{
PDFDoc doc("D:/1.pdf");
doc.InitSecurityHandler();
NumberTree pageinfo_ntree(doc.GetRoot().Get("PageLabels").Value());
if (pageinfo_ntree.IsValid())
{
pdftron::SDF::NumberTreeIterator it = pageinfo_ntree.GetIterator();
while( it.HasNext() ) {
pdftron::SDF::Obj id = it.Key();
pdftron::SDF::Obj obj = it.Value();
cout << "Key: " << id.GetNumber() << endl;
it.Next();
}
}
}
catch(...)
{
// …
}