acka.au has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I have an urgent need to work out feasibility of some Perl code to manipulate PDF files.

The requirement is to process a number of individual PDF files, add a cover page to each one with a name and address on it, then concatenate all these individal files together into one multi-document PDF.

I know there are a number of Perl modules available for working with PDFs but my success at using them in the past has been mixed. (Maybe not helped by me not having much of an understanding of the inner workings of PDF files).

I would appreciate any recommendations people could share on *which* of the available Perl modules for PDFs would best suit what I need to achieve. For example I see that CAM:PDF has a function to ADD a page, but it does not look like it can be used to INSERT a page (at the start of the document).

I'm not looking for someone to hand me the whole solution on a plate, just some advice on which would be the best tool to investigate since I don't have time to follow dead ends.

Thanks in anticipation,

Acka.au

Replies are listed 'Best First'.
Re: Perl & PDF Manipulation
by kcott (Archbishop) on Aug 27, 2013 at 09:15 UTC

    G'day Acka.au,

    I'd suggest taking a look at PDF::API2. The author of CAM::PDF has high praise for this module (see CAM::PDF - SEE ALSO [which also lists, and comments on, a couple of other PDF modules]).

    For a gentler introduction to PDF::API2, you might consider PDF::API2::Simple; although, this may be a bit too simplistic for your requirements.

    In PDF::API2 - PAGE METHODS, you'll find code examples for inserting new pages wherever you want (including a specific example of inserting at the start of the document).

    -- Ken

Re: Perl & PDF Manipulation
by Anonymous Monk on Aug 27, 2013 at 07:37 UTC
Re: Perl & PDF Manipulation
by dulwar (Monk) on Aug 27, 2013 at 10:49 UTC

    About two years back, I developed something similar, using PDF::Reuse to dynamically generate a PDF cover page based on a template and then use pdftk (check PDF::Tk for Perl integration) to prepend it to an existing PDF document.

    I tried several modules, including CAM::PDF and PDF::API2 for the merging/inserting pages and although it worked in some cases it was not as reliable as pdtfk. Whether the merging works depends a lot on the individual PDF files, so using these modules could still be a viable solution in your case. In our case the PDFs come from various sources, with different content that we have no control over. But even when using pdftk it still doesn't work with all PDF documents.