PDF::API2::Outline
An Outline object provides the user agent with a linked table of contents that may be displayed alongside the document and used for navigation. In Adobe’s Acrobat Reader, outlines are displayed in a frame called the Bookmark frame; this section sticks with the term “outline.”
To create an outline, you must first create a root outline entry
with the outlines( )
constructor,
which returns a new PDF::API2::Outline object. Once the root is
created, add outline entries with the outline( )
method; this also returns Outline
objects. You can create a hierarchy of outline entries using the
outline( )
method. Example 12-5 creates a PDF
document with 20 pages, divided into 5 sections of 4 pages each. As
each page is created, a new outline entry is added, and the entry is
linked to the page with the dest( )
method.
#!/usr/bin/perl -w # # Example 12-5. Create a bookmark frame use strict; use PDF::API2; # Used to generate the PDF output # Create a new top-level document my $pdf = PDF::API2->new( ); # Initialize the root of the outline tree my $outline_root = $pdf->outlines( ); # Use Helvetica throughout my $font = $pdf->corefont('Helvetica'); my ($page, $text); # Create four sections foreach my $s (1..4) { # Add an entry for each section. Each section has # suboutline entries my $section = $outline_root->outline( ); $section->title("Section $s"); # Add five pages for each section foreach my $n (1..5) { # Draw some text on the page ...
Get Perl Graphics Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.