private void cloneOutlines(Set<PdfOutline> outlinesToCopy, PdfOutline newParent, PdfOutline oldParent, Map<PdfPage, PdfPage> page2page, PdfDocument toDocument) {
if (null == oldParent) {
return;
}
for (PdfOutline outline : oldParent.getAllChildren()) {
if (outlinesToCopy.contains(outline)) {
PdfDestination copiedDest = null;
if (null != outline.getDestination()) {
PdfObject destObjToCopy = outline.getDestination().getPdfObject();
copiedDest = getCatalog().copyDestination(destObjToCopy, page2page, toDocument);
}
PdfOutline child = newParent.addOutline(outline.getTitle());
if (copiedDest != null) {
child.addDestination(copiedDest);
}
cloneOutlines(outlinesToCopy, child, outline, page2page, toDocument);
}
}
}