carcus88 has asked for the wisdom of the Perl Monks concerning the following question:
=begin nd Create a merged PDF from one or more PDF files using each file name as + the bookmark @param string $name Merged PDF file name @param array $pdfFiles List of PDF file names to merge @param integer $bookmarks If 1 then create bookmarks @return int 1 on success, otherwise 0 =cut sub createMergedPDF { my ($name, $pdfFiles, $bookmarks) = @_; if(!$name || ! $pdfFiles) { return 0; } my $new = PDF::API2->new; $new->preferences( -outlines => $bookmarks, # Show bookmarks -fitwindow => 1, ); my $outline_root = $new->outlines(); $outline_root->open(); foreach my $filename (@$pdfFiles) { my $pdf = PDF::API2->open($filename); foreach (1 .. $pdf->pages) { my $page = $new->importpage($pdf, $_); if($bookmarks) { my $section = $outline_root->outline(); my $title = basename($filename); $title =~ s/\.pdf//i; $section->title($title); $section->dest($page); } } } $new->saveas($name); return 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: PDF::API2 Merging PDFs and losing hyperlinks
by Athanasius (Archbishop) on Jul 18, 2012 at 04:02 UTC |