Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

PDF::API2 Merging PDFs and loosing

by carcus88 (Acolyte)
on Jul 17, 2012 at 21:14 UTC ( [id://982337]=perlquestion: print w/replies, xml ) Need Help??

carcus88 has asked for the wisdom of the Perl Monks concerning the following question:

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; }

Replies are listed 'Best First'.
Re: PDF::API2 Merging PDFs and losing hyperlinks
by Athanasius (Archbishop) on Jul 18, 2012 at 04:02 UTC

    Hello carcus88,

    I cannot reproduce your problem. I created two PDF files (using Word), each a single page containing a hyperlink. I then ran your code, with and without bookmarks enabled, and in both cases the result was a third file containing the two pages, each with its hyperlink intact and working correctly. (And the bookmarks worked correctly too).

    I’m using PDF::API2 version 2.019 (the latest version), and Strawberry Perl v5.16.0 built for MSWin32-x86-multi-thread-64int, running on Vista 32-bit.

    Athanasius <°(((><contra mundum

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://982337]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-24 03:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found