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

I'm trying to write a script which will insert text into a PDF template file and output a new PDF file.

I can do this with PDF:Reuse - but I have to specify the co-ordinates for where the text should appear. What I want, instead, is to be able to replace "place-holders" in the template file with the text.

Can any one suggest a Perl PDF module which will help with this? Or any other way of doing it?

Replies are listed 'Best First'.
Re: Perl PDF modules
by reneeb (Chaplain) on Aug 12, 2004 at 05:43 UTC
      Unfortunately, PDF::Template won't help here. It is designed to be used to generate PDF files from scratch, not read or alter them.

      ------
      We are the carpenters and bricklayers of the Information Age.

      Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

      I shouldn't have to say this, but any code, unless otherwise stated, is untested

Re: Perl PDF modules
by Plankton (Vicar) on Aug 12, 2004 at 14:31 UTC
    Or any other way of doing it?

    I like to use DocBook and xsltproc to generate HTML and then use HTMLDOC to generate my PDF. You could do the same, keeping your template as XML (DocBook) and then modify that.

    Plankton: 1% Evil, 99% Hot Gas.

      Another way to do the same thing is to use LaTeX for your template and use pdflatex to generate PDF. Same difference.

      Don't know a way to force PDF to be rewritten when you've got an extant PDF template, though

Re: Perl PDF modules
by freddo411 (Chaplain) on Aug 12, 2004 at 17:49 UTC
    This node "PDF generation" has a good discussion and answers.

    In particular, there are modules that support exactly what you want to do, but you'll have to pay a bit to get the underlying tools.

    -------------------------------------
    Nothing is too wonderful to be true
    -- Michael Faraday

Re: Perl PDF modules
by clscott (Friar) on Aug 12, 2004 at 17:59 UTC
      Nope, for the same reason I mentioned earlier. Those modules, like PDF::Template only create new files. They will not edit existing files or use existing files as starting points. You will need something similar to PDF::Reuse to do this.

      ------
      We are the carpenters and bricklayers of the Information Age.

      Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

      I shouldn't have to say this, but any code, unless otherwise stated, is untested

Re: Perl PDF modules
by mkenney (Beadle) on Aug 15, 2004 at 03:26 UTC
    This is one of the biggest requests for real life Perl uses. PDF:Reuse has been the best solution I have found so far. I believe that his is a good area for a new modlule but I'm not able to write it yet. PDFs are very common yet there is not GREAT templating system out there yet. PDF:Reuse is the best one I have found so far...