I have a PDF which doesn't have an index (which I believe is called an "outline")
It is not. An index is an arbitrary collection of entries, e.g.
Outline, in PDF parlance, is rather a set of bookmarks (that's what they are called in Acrobat UI), most often, but not necessarily, posing as TOC, leading to anywhere within the document or within universe, or triggering any other action in JS-enabled viewer.
Never used PDF::API2::Outline, but FWIW:
use strict;
use warnings;
use PDF::API2;
my $doc = PDF::API2-> open( 'sample.pdf' ); # Assuming it to have
+at least
# 2 pages
$doc-> outlines
-> outline
-> dest( $doc-> openpage( 1 )) # All this chaining is
+ not
-> title( '1st page') # really necessary, do
+ing it
-> parent # just for fun.
-> outline
-> title( '2nd page')
-> open
-> outline
-> title( 'top of 2nd page' )
-> dest( $doc-> openpage( 2 ), '-xyz' => [ 0, 0, 0 ])
-> parent
-> outline
-> title( '2nd page, 500 pts from top edge' )
-> dest( $doc-> openpage( 2 ), '-xyz' => [ 0, 500, 0 ]);
$doc-> preferences( '-outlines' => 1 );
$doc-> saveas( 'sample+.pdf' );
Reading the source notwithstanding, $doc-> outlines won't do any good if a document being opened already contains Outlines -- not your case, I understand. Just try reading saved document again, to see. And re-blessing won't help. Distribution needs to be patched.
Bookmarking to locations within the page (above) will work if document is viewed with sufficient zoom. Changing zoom when jumping to destination is possible, but I personally think it's rather impolite.
|