private Integer getBookmarkDestinationPage(PDOutlineItem item) throws IOException, COSLoadException { if (item == null) { return null; } if (item.getDestination() != null) { PDExplicitDestination destination = item.getDestination().getResolvedDestination(getDocument()); if (destination != null) { PDPage page = destination.getPage(getDocument()); return page.getNodeIndex() + 1; } } if (!(item.cosGetField(PDOutlineItem.DK_A) instanceof COSNull)) { COSDictionary cosDictionary = (COSDictionary) item.cosGetField(PDOutlineItem.DK_A); COSArray destination = getCOSArrayFromDestination(cosDictionary); return getPageFromCOSArray((COSArray) destination); } return null; }
private void getBookmarks(PDOutlineNode parent, List<APDMetaObject> bookmarks) throws IOException, COSLoadException, COSRuntimeException { if (parent == null) { return; } @SuppressWarnings("unchecked") List<PDOutlineItem> children = parent.getChildren(); for (PDOutlineItem child : children) { COSObjectContext context = new COSObjectContext(child); Bookmark bm = new Bookmark(getOrCreateUID(context), context); setBookmarkDestination(bm, child); int objectNumber = child.cosGetObject().getIndirectObject().getObjectNumber(); bm.setObjectNumber(objectNumber); bm.setText(child.getTitle()); if(child.getChildren().size() > 0) { getBookmarks(child, bm.getChildren()); } bookmarks.add(bm); } }
private URI getBookmarkDestinationUri(PDOutlineItem item) { if (!(item.cosGetField(PDOutlineItem.DK_A) instanceof COSNull)) { COSDictionary cosDictionary = (COSDictionary) item.cosGetField(PDOutlineItem.DK_A); COSObject destination = cosDictionary.get(COSName.create("URI")); if (!(destination instanceof COSNull)) { if (destination instanceof COSString && destination.getValueString(null) != null && destination.getValueString(null).length() > 0) { try { return new URI(destination.getValueString(null)); } catch (URISyntaxException e) { System.out.println("Bookmark Destination Uri Syntax incorrect." + e.getMessage()); } } } } return null; } /***********************************************************************************