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

I'm looking for a way to be able to fill in PDFs with information from a database.

I want to let the layout people make the layout and use some sort of template system to define the data fields. So they could make the form and then say put in :
<VARNAME: firstName>
where they want the first name to be. Ideally what ever color/size/font/etc they use there would be the one that is used when filling out the that field. I've found some solutions but none seem to take it to this level and it seems like this must be a common want and probably has a solution already.

I'm must be making this harder then it needs to be again! Please help me out before I hurt my head to much hitting it against the wall...

Replies are listed 'Best First'.
Re: PDF Template Solution- Why is this so hard?
by marto (Cardinal) on Aug 10, 2010 at 15:58 UTC

    Have you looked at using something like PDF::Reuse? If so what have you tried and what problems did you experience, purely so we don't all reply listing things you've already looked at.

      I did start trying PDF::Reuse a bit ago. One of the things that made me nervous is that it appeared like it is no longer and active project and only worked with older versions of PDF documents. Sounded like Acrobat 5 version? I don't fully get the different versions yet but it struck me as something that could make it an issue with PDFs created in newer programs? Am I thinking wrong about this, or is this not a big deal and most programs still use the older version of PDF?

      I'm obviously struggling some to wrap my arms around this...

      Thanks for the help!!!

        Modern versions of PDF readers will be able to read older pdf file formats. I think I'm pretty safe in saying that they are backwards compatible. Various topics exist here on the subject of PDF version support among modules (see Extracting content text from PDFs and Extracting text from PDF. No really among others), even Open Office (v3.2 on Linux) exports PDF v1.4 files. Is there a particular feature of the PDF format (greater than v1.4) that you need to accommodate? IF all you are doing is mass populating text within a template PDF, ensure the person supplying the template is aware of your version restrictions.

        I'm sure others will pitch in with their experiences on this subject.

Re: PDF Template Solution- Why is this so hard?
by psini (Deacon) on Aug 10, 2010 at 16:13 UTC

    I've written a module for templating ODT files (OpenOffice documents) in order to do exactly the thing that you ask: I write a template using OpenOffice, a perl program expands the template using data from a given structure, then OpenOffice converts the resulting ODT in a PDF file.

    The module is in pre-alpha stage: it works (mostly) but has no test suite and poor documentation, but if you are interested in it I can make it downloadable somewhere.

    Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

      Sounds interesting but probably won't work for this project yet. I'm hoping to turn over the template to the layout people and it sounds like I would have to hand hold (i.e. do) most of the templates for them if trying this;-)

      Thank-you for the very generous offer!!!

        Why? My templates are valid OpenOffice documents and the markup is something like "{$var}" to interpolate a variable, {if $var para} to have a conditional paragraph, and so on. The skills needed to generate a template file should be at the same level than those for using TT to generate HTML pages.

        Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

      Hi psini,

      That sounds interesting. I might have a need for something like that as well in the future and I might be willing to contribute to the module if there is anything useful I can do.
      Would you be able to make it available for download somewhere?

        I've posted the code in my scratchpad psini's scratchpad for anyone interested in it. Any feedback will be greatly appreciated.

        I wrote the module about one year ago, but I'll start using it next month in a project, so chances are high that it will be largely improved and/or modified in the next two or three months.

        Update:

        The code for the module is now exported nightly from SVN into OpenOffice-Template.zip

        Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

        Sorry for the late answer but I was away. I'll be back to my office near the end of next week and I'll find a place to put the code for download.

        Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."