PGTS PGTS Pty. Ltd.   ACN: 007 008 568

point Site Navigation

point Other Blog Threads

  Valid HTML 4.01 Transitional

   Give Windows The Boot!
   And Say Goodbye To Viruses!


   If you own a netbook/laptop~
   Download Ubuntu Netbook!

PGTS Humble Blog

Thread: Tips/Tricks For Programming etc

Gerry Patterson, The World's Most Humble Blogger

Converting HTML to PDF.

Chronogical Blog Entries:

Date: Sat, 21 Jan 2012 20:47:18 +1100

PDF has become a de-facto standard for transporting invoices, statements and other common documents which used to be transported by ordinary mail. But getting a convenient open source solution solution for producing PDF files can be difficult

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/
ps2pdf /data/html/

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.

Other Blog Posts In This Thread:

Copyright     2012, Gerry Patterson. All Rights Reserved.