Greetings,
I'm currently fumbling over how to get PDF::API2 to merge to PDFs together and retain the hyperlinks. It seems to wipe them out and I don't see any options for this. Could anyone shed some light on this? Here is an example of how they are being merged. I basically take 2 more more files in the $pdfFiles array and merge them into one file $name and optionally create bookmarks using each file name.
=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;
}