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;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.