Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

using perl to build documents off of pdf templates

by nmerriweather (Friar)
on Jul 30, 2002 at 07:36 UTC ( #186145=perlquestion: print w/replies, xml ) Need Help??

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

for the life of me, i can't figure this out.

I have some nicely designed templates in a pdf file. 1 page. they're for tickets. art, text, everything -- they look pretty damn nice.

i wanted to use perl to take the one page, which holds 10 2"x4" tickets, and duplicate it as needed into 1 document -- substituting ###ticket### in the document for the appropriate ticket number

Hours of searching the docs, web, and this archive have nearly taught me how to build the pdf from scratch and solve my problem -- but still no clue how to use perl for templating off the one pdf

right now, the only thing i've managed to do, is use importpage from PDF::API2 to duplicate the page. still no idea how to replace text in it.

hopefully someone can help me out? maybe even suggest a better method -- i think with this method i'm duping the font data per-page bloating the filesize

  • Comment on using perl to build documents off of pdf templates

Replies are listed 'Best First'.
Re: using perl to build documents off of pdf templates
by jmcnamara (Monsignor) on Jul 30, 2002 at 08:10 UTC
      Gah. PDF::Template requires items that are not found in the CPAN. That's pretty lame to have cool things not yet in the CPAN, and for a CPAN thing to require things that aren't in the CPAN. {sigh}

      -- Randal L. Schwartz, Perl hacker

Re: using perl to build documents off of pdf templates
by greenFox (Vicar) on Jul 30, 2002 at 13:04 UTC
    Another solution which may be worth looking at is to convert your pdf to postscript (with something like ghostscript). Postscript is an open format and the file format is text so you can edit it any-way you like with perl :) It wouldn't make a lot of sense to go this way if your template was changing often or if you were doing a substantial edit but for changing one value (if I have understood you correctly) it might be a neat hack.

    --
    Until you've lost your reputation, you never realize what a burden it was or what freedom really is. -Margaret Mitchell

      That's a great idea. The template was made in illustrator, so i can just save to an eps file. I'm sure there will be a mod or something to convert that file to pdf!
Re: using perl to build documents off of pdf templates
by traveler (Parson) on Jul 30, 2002 at 15:38 UTC
    I tried to do something similar and had a difficult time too. I found that Text::PDF comes with a tool called pdfstamp. This tool allows placing text anywhere "on" a PDF document in a choice of fonts. It is a perl script and it can easily be incorporated into other scripts. I'd use this to put the numbers on the tix. Then you wouldn't have to modify the template. The only "trick" is to figure out where on the page the numbers go, but that is not too tricky: I put footers on my pages on the third try...

    HTH, --traveler

      ok

      i ended up sticking w/pdf api 2

      its got a text feature that can 'stamp' like the text::pdf suggestion -- so thanks on that!

      i just used api:2, because it lets you clone pages

      its a 1meg file though - ugh - so the overhead sucks for constant use. i did something in 'bad style' -- and had the use pdf:: in a seperate file that i 'do' as needed. i'm sure i'd be hung for that -- but it works :)

Re: using perl to build documents off of pdf templates
by tjh (Curate) on Jul 30, 2002 at 19:30 UTC
    There's an article on ibm.com that discusses customizing pdf's via a middle ASCII postcript step and includes a small Perl application in the example. It's here at "Personalizing PDF files".

    It's a fairly plain language description of the process. It's a shame there's no simple CPAN solution for filling in fields in a pre-existing pdf form and outputting the new file. Maybe I missed it, but I can't find one either. Maybe someone could concoct one that hid the PS middle step </hint>. :)

    Also, Adobe has their FDF (File Document Format) which, as I understand it, is a text file format (constructed via CGI from some source, ie. html form) that can be served to a browser (which has Acrobat Reader installed), and the Reader will automatically retrieve and serve the applicable PDF form with the fields properly incorporated.

    There's quite a bit of discussion (Google Groups)about using FDF via CGI indicating that several people have trouble understanding how to do it, but it certainly looks do-able. I haven't had occasion to do this, but it looks interesting so far.

    HTH

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2019-09-22 15:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (273 votes). Check out past polls.

    Notices?