Outlines can be included in the PDF document to allow quick access to specific pages in the PDF document. These can be added to the document in one of two ways.
Outlines can be added to the document through the Outlines property of the Document object. The Document contains a hierarchical list of outlines to associate with the Document. These outlines have properties for controlling the color and style as well as a property to control if it is expanded by default:
[Java]
// Create a PDF Document
Document document = new Document();
// Add three blank pages
document.getPages().add(new Page(PageSize.LETTER));
document.getPages().add(new Page(PageSize.LETTER));
document.getPages().add(new Page(PageSize.LETTER));
// Add a top level outline and set properties
Outline outline1 = document.getOutlines().add("Outline1");
outline1.setStyle(TextStyle.BOLD);
outline1.setColor(new RGBColor(255, 0, 0));
// Add child outlines
Outline outline1A = outline1.getOutlines().add("Outline1A", new ZoomDestination(2, PageZoom.FIT_PAGE));
outline1A.setIsExpanded(false);
Outline outline1A1 = outline1A.getOutlines().add("Outline1A1", new XYDestination(2, 0, 0));
Outline outline1A2 = outline1A.getOutlines().add("Outline1A2", new ZoomDestination(2, PageZoom.FIT_HEIGHT));
Outline outline1B = outline1.getOutlines().add("Outline1B", new ZoomDestination(2, PageZoom.FIT_WIDTH));
// Add a second top level outline
Outline outline2 = document.getOutlines().add("Outline2", new XYDestination(3, 0, 300));
// Add a child outline
Outline outline2A = outline2.getOutlines().add("Outline2A");
// Save the PDF document
document.draw("[PhysicalPath]/MyOutlines.pdf");
The location that the outline links to can be specified using Action objects. There are three Action objects included with Generator for Java:
- UrlAction - Links to an external URL.
- XYDestination - Links to an XY coordinate on a page.
- ZoomDestination - Links to a page at a specified zoom level.
Outlines can also be added to the document using the Bookmark Page Element. This object can be used to add outlines to the root of the document or to add outlines beneath a parent outline. These bookmarks always link to a coordinate on the page that contains them:
[Java]
// Create a PDF Document
Document document = new Document();
// Create three page objects
Page page1 = new Page(PageSize.LETTER);
Page page2 = new Page(PageSize.LETTER);
Page page3 = new Page(PageSize.LETTER);
// Add a top level Outline
Outline parentOutline = document.getOutlines().add("Parent Outline");
// Add a top level bookmark
page1.getElements().add(new Bookmark("Top level bookmark to page 1", 0, 0));
// Add child bookmarks
page1.getElements().add(new Bookmark("Bookmark to page 1", 0, 0, parentOutline));
page2.getElements().add(new Bookmark("Bookmark to page 2", 0, 0, parentOutline));
page3.getElements().add(new Bookmark("Bookmark to page 3", 0, 0, parentOutline));
// Add the three pages to the document
document.getPages().add(page1);
document.getPages().add(page2);
document.getPages().add(page3);
// Save the PDF document
document.draw("[PhysicalPath]/MyOutlines.pdf");