NOTE: Bookmarks imported from alien PDF files MUST be cloned
before being added.
*/
bookmark.getBaseDataObject().put(PdfName.Parent,getBaseObject());
PdfInteger countObject = ensureCountObject();
// Is it the first bookmark?
if(countObject.getValue() == 0) // First bookmark.
{
getBaseDataObject().put(PdfName.First,bookmark.getBaseObject());
getBaseDataObject().put(PdfName.Last,bookmark.getBaseObject());
countObject.setValue(countObject.getValue()+1);
}
else // Non-first bookmark.
{
PdfReference oldLastBookmarkReference = (PdfReference)getBaseDataObject().get(PdfName.Last);
getBaseDataObject().put(PdfName.Last,bookmark.getBaseObject()); // Added bookmark is the last in the collection...
((PdfDictionary)File.resolve(oldLastBookmarkReference)).put(PdfName.Next,bookmark.getBaseObject()); // ...and the next of the previously-last bookmark.
bookmark.getBaseDataObject().put(PdfName.Prev,oldLastBookmarkReference);
/*
NOTE: The Count entry is a relative number (whose sign represents
the node open state).
*/
countObject.setValue(countObject.getValue()+Math.signum(countObject.getValue()));
}
return true;
}