Reputation: 362
I have built a tree view to show the bookmarks of a given PDF document.
Using iTextSharp I get the bookmarks in a List object and use the Title value to show on the tree view, no problem.
The problem comes when I want the tree view node to reference a page number in the PDF document.
Some PDF documents have a value for Title, Page and Action for example:
Title: "Title Page",
Page: "1 XYZ -3 845 1.0",
Action: "GoTo"
However, others are in this format:
Title: "Title Page",
Named: "G1.1009819",
Action: "GoTo"
I have no idea what to do this the "Named" value. I have tried going through all the links in the document and comparing the value to the destination value of the link, but with no luck.
Does anyone know what this "Named" property represents?
Upvotes: 2
Views: 1370
Reputation: 77528
It's a named destination, see the keyword list for some examples. It is a very common way to mark destinations in a document.
What do you want to do with the named destinations?
Do you want to consolidateNamedDestinations()
so that they are no longer named destinations, but links to the specific place in the document.
Or do you want to create a link to a named destination? (That's probably more work. I don't think there are examples at hand.)
If you browse the examples, you'll discover the LinkActions
where we use the SimpleNamedDestination
object to retrieve the named destinations almost the same way you retrieve bookmarks using the SimpleBookmark
class.
This code snippet gives us the bookmarks in the form of an XML file:
public void createXml(String src, String dest) throws IOException {
PdfReader reader = new PdfReader(src);
HashMap<String,String> map = SimpleNamedDestination.getNamedDestination(reader, false);
SimpleNamedDestination.exportToXML(map, new FileOutputStream(dest),
"ISO8859-1", true);
reader.close();
}
See destinations.xml for the result.
The code is much easier because the structure isn't nested: each name corresponds with a single destination.
Upvotes: 2