The code sample below creates a three-page document with
destinations on each page. You can test the resulting PDF by
clicking on the links below:
Link to Chap1
Link to Chap2
Link to Chap3
Please note that this is only a code fragment; the complete source code is part of the jPDF distribution.
// Create a document with 3 pages:
doc = new PdfDocument();
Page page1 = Page.createInstance(doc);
drawOnPage(page1, "Check destination from Acrobat by using the menu
item View->Navigation Panels->Destinations");
Page page2 = Page.createInstance(doc);
drawOnPage(page2, "Destinations are triggered by using a URL of the form http://www.mydomain.com/myDoc.pdf#nameddest=Chap2");
Page page3 = Page.createInstance(doc);
drawOnPage(page3, "Last test to demonstrate how you can position the destination using a position+zoom factor");
// Get the creator module and generate the destinations:
CreatorModule creatorModule = doc.getCreatorModule();
LocalPageDestination dest1 = LocalPageDestination.createInstance(doc);
dest1.setPageIndex(1);
creatorModule.setNamedDestination("Chap1", dest1);
LocalPageDestination dest2 = LocalPageDestination.createInstance(doc);
dest2.setPageIndex(2);
creatorModule.setNamedDestination("Chap2", dest2);
LocalPageDestination dest3 = LocalPageDestination.createInstance(doc);
dest3.setPageIndex(3);
ZoomPosition zoom = new ZoomPosition(new Integer(15), new Integer(30), new Float(3));
dest3.setZoom(zoom);
creatorModule.setNamedDestination("Chap3", dest3);
// Save the document:
doc.saveAs("MySampleDestinations.pdf");
doc.close();