Tuesday, December 06, 2005

Printing an invoice from web

I found my self in the need of printing an invoice into a printed form from a web based application written in PHP + Apache + PostgresSQL, the objetive was that the data should fit precisely in the printed invoice fields boxes.

After some research i couldn't find any relevant information about printing invoices from web using php, so i started my own solution. If you print html directly from the web browser its harder to fit that displayed data in the printed paper and using different browers should affect the position of displayed and printed data, so printing html directly from browser was not an option. I thought about create a pdf to not deal with different browsers options and have some kind of compatibility, there where three choices : convert html to pdf (http://www.rustyparts.com/pdf.php), create postscript an convert it to pdf (http://pslib.codigolivre.org.br) or create the pdf directly (http://www.pdflib.com/).

For the first one it was not possible to get the html fit a precisely position and with the convertion from html to pdf you get just some kind of approach without maintain the positions of elements. For the second one you can set x,y coordinates for the data you want to display and if you have a postscript printer it can send directly to it, so i choose this one. The last one could be a choice too but it could be useful if you can send the postscript directly to the printer.

For creating postscript i used Pslib which is a library written in php an then converted it to pdf using ps2pdf which comes with some Linux distros.

If anybody knows another solution, please let me know. :P

No comments: