# examples using PDF::Template

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
I have a possible project I am looking into that is basically creating
a "mail-merge" utility that would chew through a big CSV spreadsheet
and merge the fields into a template to generate a big .pdf document.
The reason the client wants to go .pdf is to have a "print ready"
format.

After poking through CPAN, it looks like PDF::Template and/or
PDF::Create are along these lines.... It is a little unclear to me how
involved it would be to set up the template that I would "merge" into.
There seem to be a LOT of parameters that would need to be set up in a
root document, and I am wondering if there is a reasonably easy way to
do this.

Like...
- Can I take an existing authored .pdf page and clone all the
margins settings and stuff like that?

- Can I author a template with any special tags where I want to plug
in my variable fields?

If you have any tips, tutorials, or examples illustrating these modules
that would help me determine if this is the way to go....

TIA,
Dan

## Re: examples using PDF::Template

botfood wrote:

> - Can I take an existing authored .pdf page and clone all the
> margins settings and stuff like that?

Probably not.

> - Can I author a template with any special tags where I want to plug
> in my variable fields?

Probably not.

A PDF file includes a cross reference that has byte offsets to all of
the objects in the file. Any modifications in the PDF file will require
an update of the cross reference.

> If you have any tips, tutorials, or examples illustrating these modules
> that would help me determine if this is the way to go....

The first thing is to become familiar with the PDF spec. The spec has
been available on Adobe's web site. I can't find it right now. The file
name is PDFReference15_v6.pdf. (A subsequent update may have a different
file name.)

PDF files were not designed for easy modification, so trying to fill in
a template can be as much effort as creating a new PDF from scratch.

As for PDF::Template and PDF::Create, I don't use them. I couldn't find
documentation for them, and they do much more than I need them to. I
wrote my own module to create simple PDFs. In order to use that module,
one would have to be very familiar with portions of the PDF spec.

Try posting to comp.text.pdf and see if anyone there has some ideas.

## Re: examples using PDF::Template

botfood wrote:
> I have a possible project I am looking into that is basically
creating
> a "mail-merge" utility that would chew through a big CSV spreadsheet
> and merge the fields into a template to generate a big .pdf document.
> The reason the client wants to go .pdf is to have a "print ready"
> format.
> --------------------------

after a night of poking around, and you all's input, it looks like
creating .pdf files on the fly is a pretty involved and painful
process. PDF::Template has potential for what I want to do, but
requires learning special XML syntax to set up the template, and buying
the PDFlib for about $450. PDF::Create has some simple capabilities, but neither look straightforward to use in a mail-merge application as there are some complex issues with pagination and text position. Neither module had very complete docs, and I couldn't find any reasonably complete tutorials or examples online. I read thru the overview and some syntax of the actual .pdf spec on the adobe site... and while a super simple layout might be pretty easy to code, it would get REAL deep real fast. so.... just thought I'd post a followup in case somebody googles later. Its looking to me like its a lot easier to generate the output is a text, html, or other man-readable format and then use a cheap "print to pdf" convertor at the backend. if there is somebody out there who has actually used PDF::Create and/or PDF::Template and would like to share some thoughts on the capabilities/limitations, ease of use, examples, etc, I still think it would be great to share some knowledge of these packages. I realize that some people feel this group is for asking questions after you get stuck... but I HOPE there are also people out their interested in sharing experiences with specific packages to help others evaluate alternatives before investing a lot of learning time and test code. d ## Re: examples using PDF::Template botfood wrote: > botfood wrote: > >>I have a possible project I am looking into that is basically > > creating > >>a "mail-merge" utility that would chew through a big CSV spreadsheet >>and merge the fields into a template to generate a big .pdf document. >>The reason the client wants to go .pdf is to have a "print ready" >>format. >>-------------------------- > > > after a night of poking around, and you all's input, it looks like > creating .pdf files on the fly is a pretty involved and painful > process. PDF::Template has potential for what I want to do, but > requires learning special XML syntax to set up the template, and buying > the PDFlib for about$450. PDF::Create has some simple capabilities,
> but neither look straightforward to use in a mail-merge application as
> there are some complex issues with pagination and text position.
> Neither module had very complete docs, and I couldn't find any
> reasonably complete tutorials or examples online.
>
> I read thru the overview and some syntax of the actual .pdf spec on the
> adobe site... and while a super simple layout might be pretty easy to
> code, it would get REAL deep real fast.
>
> so.... just thought I'd post a followup in case somebody googles later.
> Its looking to me like its a lot easier to generate the output is a
> text, html, or other man-readable format and then use a cheap "print to
> pdf" convertor at the backend.
>
> if there is somebody out there who has actually used PDF::Create and/or
> PDF::Template and would like to share some thoughts on the
> capabilities/limitations, ease of use, examples, etc, I still think it
> would be great to share some knowledge of these packages.
>
> I realize that some people feel this group is for asking questions
> after you get stuck... but I HOPE there are also people out their
> interested in sharing experiences with specific packages to help others
> evaluate alternatives before investing a lot of learning time and test
> code.
>
> d
>

Ghostscript to convert it to PDF? Postscript is probably easier to
create on the fly than PDF (not sure, not much experience here) and
Ghostscript works quite well for creating PDF files. I just checked and
there is a module PostScript::Simple on CPAN (among quite a few others)
which might do what you want.

It is also quite simple to create a Postscript "template" with
placeholders in it and then replace these placeholders with your actual
data using Perl. To create such a template you can use for example a
word processor (or spreadsheet or whatever) and save the document as
Postscript to a file. I did something like that to provide a legacy
application with nicely formatted reports.

Hope this helps.

Regards,

Constantin

## Re: examples using PDF::Template

wow,

hey, this may be exactly what I need! The formatting looks simple, and
I think the printer will accept either PostScript or eps files. Looks
like a much cleaner solution than .pdf !

mucho gracias,
d

## Re: examples using PDF::Template

....after looking at what available, I'm a little confused about what to
do next. I have an old version of perl from Activestate that I use for
development (5.005 build 522) as a lowest common denominator. I am not
SURE what version my usual webhost as installed, but its probably 5.6
or 5.8 by now?

anyway, the issue is that while PostScript::Simple is listed on CPAN,
it is NOT in the activestate download ppm. there is a similar package
PostScript, but only compiled for perl 5.8 and by a different author
with different methods.

so.... I am unsure which way to go that would allow me to code and test
at home on my PC and have the most likely chance of asking my webhost
to install if they haven't already.

PostScript  from activestate, or PostScript::Simple from CPAN ???? and
how do I get either of them running on my PC under old perl without
having compilers and all that?

## Re: examples using PDF::Template

: I think the printer will accept either PostScript or eps files. Looks
: like a much cleaner solution than .pdf !

Then maybe it's worth looking at the Template Toolkit
(namespace Template at CPAN)

http://www.template-toolkit.org/examples/ps/index.html
http://www.template-toolkit.org/info.html

--
,::::,
::    :    Nuba Rodrigues Princigalli    _____________
:. O-O:                                 |        '\\
:   >     Web Design and Development   |        ' ____|_
____\  - ._.   Computational Mathematics   |   +    '||::::::
/'    \ -::' .'                              |        '||_____|
/. ,-    O    < \               www.nuba.tk   '________|_____|
(\ <'     '  |\ / '-.___    nuba@dcc.ufmg.br   ___/____|___\___
_.\__\________\_\___/), |\____________________|    _    '  <<<:|
|_________'___o_o|

## Re: examples using PDF::Template

>after a night of poking around, and you all's input, it looks like
>creating .pdf files on the fly is a pretty involved and painful
>process. PDF::Template has potential for what I want to do, but
>requires learning special XML syntax to set up the template, and buying
>the PDFlib for about $450. PDF::Create has some simple capabilities, >but neither look straightforward to use in a mail-merge application as >there are some complex issues with pagination and text position. [snip] >if there is somebody out there who has actually used PDF::Create and/or >PDF::Template and would like to share some thoughts on the >capabilities/limitations, ease of use, examples, etc, I still think it >would be great to share some knowledge of these packages. Well, I can't share any experience on the packages you mention, but I may try insisting on the pdfLaTeX route. See this fictious example: #!/usr/bin/perl use strict; use warnings; die "Usage:$0 <template>\n" unless @ARGV == 1;

open my $fh, '|-', 'pdflatex' or die "Can't pipe into pdfLaTeX:$!\n";
select $fh; while (<>) { s/ <<CODE>> / \lstinputlisting /x; print; } __END__ called with the following template as argument \documentclass[a4paper,12pt] \title{A Minimal Example} \author{Me Myself} \date \usepackage \usepackage[bookmarks=true, bookmarksnumbered=true, colorlinks=true, linkcolor=blue, pdfpagemode=None, pdfstartview=FitH] \makeatletter \newcommand\org@maketitle{} \let\org@maketitle\maketitle \def\maketitle{% \hypersetup{ pdftitle=, pdfauthor=, pdfsubject={Nothing more than a minimal example}, pdfkeywords={minimal example} }% \org@maketitle } \makeatother \usepackage \begin \maketitle \lstset{language=Perl, basicstyle=\small\ttfamily, commentstyle=\color, stringstyle=\color, keywordstyle=\color, backgroundcolor=\color[gray], xleftmargin=2em, frame=single, framexleftmargin=2em, showstringspaces=no, numbers=left, numberstyle=\tiny, numbersep=2em} \section{What is all this about?!?} This is just a minimal example here's the code I used to generate this document from a template: <<CODE>> \end Running the perl program will leave a texput.pdf output file in the cwd. If you want to see a sample output, you can find it at <http://mosquito.scumm.it/~blazar/example.pdf . Of course all this is very rough, and I remember having seen more refined examples somewhere, however I don't have any link offhand. IIRC someone even set up a TeX sort of daemon especially aimed at "this kinda things"... >I realize that some people feel this group is for asking questions >after you get stuck... but I HOPE there are also people out their >interested in sharing experiences with specific packages to help others >evaluate alternatives before investing a lot of learning time and test >code. Hope the above helps. Of course the solution I'm proposing requires having a TeX system installed, which is not a problem for me, since I need it anyway... Michele -- ->(map substr (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<ZS(G.DZZ9OX0Z')=~/./g)x2,$_, 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH, ## Re: examples using PDF::Template >I have a possible project I am looking into that is basically creating >a "mail-merge" utility that would chew through a big CSV spreadsheet >and merge the fields into a template to generate a big .pdf document. >The reason the client wants to go .pdf is to have a "print ready" >format. Not really an answer to your question, but have you considered using pdf(La)TeX for this purpose? Of course you can still use perl to build the source... Michele -- ->(map substr (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<ZS(G.DZZ9OX0Z')=~/./g)x2,$_, 256),7,249);s/[^\w,]/ /g;$ \=/^J/?\$/:"\r";print,redo}#JAPH,