http://www.perlmonks.org?node_id=878586


in reply to PDF File Merging Data

Another option could be to have your template in an easily-readable format, such as a text file. Then the reading part becomes trivial, can replace your placeholders as they are encountered, and write to a pdf using pdf::create.

The reason I offer this solution as an alternative is due to the fact that I must be quite dense - I tried figuring out how pdf::reuse works, even looked at the PDF::Reuse::Tutorial, and have no clue how you could find the tags and replace them on the fly using that. I could just be a little low on IQ points, but I find pdf::create very easy to use...

Replies are listed 'Best First'.
Re^2: PDF File Merging Data
by LanX (Saint) on Dec 22, 2010 at 20:54 UTC
    >I tried figuring out how pdf::reuse works, even looked at the PDF::Reuse::Tutorial, and have no clue how you could find the tags and replace them on the fly using that.

    Can't say much about this, the docs seem to talk about form fields and mention JS, so it might not be what the OP wanted.

    Anyway the OP was talking about "replacing placeholders".

    With a PDF version where allowed fields are completely filled with blind text in a dedicated font, pdftohtml -xml could easily be used to parse and grep the absolute positions for these text boundaries.

    And plotting text by absolute positions is trivial with PDF::Reuse. (of course into a PDF without blind text)

    But as I already said, one has to care about line breaks and staying within bounding boxes, cause PDF is not HTML, it's a print format!

    see also: Parsing PDFs by text position?

    Cheers Rolf

Re^2: PDF File Merging Data
by Anonymous Monk on Dec 22, 2010 at 17:25 UTC
    the flier is mostly images, it is a professionally designed flier for our members to share a free giveaway website we built for them to build their organization.

    So, if I had it done in HTML would that work? or does it have to be text? I have looked over the module you suggested, but I don't see an easy way to test it.

    thx,
    Richard
      Ahh, images. I don't see anything in pdf::create that allows for embedding images.

      In that case, you could try the module Rolf suggested (pdf::reuse), using the prText method to write to the existing template. But instead of replacing tags, set up the position of each dynamic data element in your Perl script (e.g. ~fullname~ has a position of {10,50}). Then, store/read the values for replacement separately. Doesn't have to be text - could get fancy and read them out of an Excel file, or database...