I have discovered that the easiest way to create PDF documents is to create the initial document as HTML. There are, of course, a large number of packages and programs to create HTML, and I have developed numerous scripts which generate HTML. Having created the HTML I then convert it to PDF.
You need the packages that will help with the conversion. These are the html2ps utility which converts HTML to postscript and the ps2pdf utility from the ghostscript package.
In Ubuntu, you can get them with this command:
sudo apt-get install gs html2ps
First create your HTML. for example, you might have a perl CGI script which reads a tab-delimited file and creates an invoice. Let's suppose your invoice is called /data/html/0000999.html. Assuming that your html will display ok (i.e. paths etc have been setup correctly), You can easily create your PDF file with the following commands:
html2ps /data/html/0000999.html > /data/html/0000999.ps ps2pdf /data/html/0000999.ps
This will create the file /data/html/0000999.pdf in the output folder.
You can add page numbers with the -n option.
Note: The script html2ps is written in perl.
G. Patterson.   T/A PGTS ABN: 99885392845