Am 15.12.2018 um 21:46 schrieb Tilman Hausherr:
However all this means that I the example code should be improved to
include named destinations.
The example has now been improved, here's the new method. But you using
findDestinationPage() is fine too.
public void printBookmark(PDDocument document, PDOutlineNode
bookmark, String indentation) throws IOException
{
PDOutlineItem current = bookmark.getFirstChild();
while( current != null )
{
// one could also use current.findDestinationPage(document)
to get the page number,
// but this example does it the hard way to explain the
different types
// Note that bookmarks can also do completely different
things, e.g. link to a website,
// or to an external file. This example focuses on internal
pages.
if (current.getDestination() instanceof PDPageDestination)
{
PDPageDestination pd = (PDPageDestination)
current.getDestination();
System.out.println(indentation + "Destination page: " +
(pd.retrievePageNumber() + 1));
}
else if (current.getDestination() instanceof
PDNamedDestination)
{
PDPageDestination pd =
document.getDocumentCatalog().findNamedDestinationPage((PDNamedDestination)
current.getDestination());
if (pd != null)
{
System.out.println(indentation + "Destination page:
" + (pd.retrievePageNumber() + 1));
}
}
else if (current.getDestination() != null)
{
System.out.println(indentation + "Destination class: "
+ current.getDestination().getClass().getSimpleName());
}
if (current.getAction() instanceof PDActionGoTo)
{
PDActionGoTo gta = (PDActionGoTo) current.getAction();
if (gta.getDestination() instanceof PDPageDestination)
{
PDPageDestination pd = (PDPageDestination)
gta.getDestination();
System.out.println(indentation + "Destination page:
" + (pd.retrievePageNumber() + 1));
}
else if (gta.getDestination() instanceof
PDNamedDestination)
{
PDPageDestination pd =
document.getDocumentCatalog().findNamedDestinationPage((PDNamedDestination)
gta.getDestination());
if (pd != null)
{
System.out.println(indentation + "Destination
page: " + (pd.retrievePageNumber() + 1));
}
}
else
{
System.out.println(indentation + "Destination
class2: " + gta.getDestination().getClass().getSimpleName());
}
}
else if (current.getAction() != null)
{
System.out.println(indentation + "Action class: " +
current.getAction().getClass().getSimpleName());
}
System.out.println( indentation + current.getTitle() );
printBookmark( document, current, indentation + " " );
current = current.getNextSibling();
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]