Mango's PHP PostScript Functions


The latest techniques we've been playing with involve using a PHP script on our server in Michigan to print to a remote printer at our office in Vancouver.  In the past we've done this by generating an XHTML document with high-resolution images and simply prompting the user to print it.  This worked, but if any sort of precision was required, the user had to configure their browser's page setup just so, and to make things even more difficult, different browsers required different settings.

Enter PostScript, a language understood by many laser printers.  With PostScript, we can go directly from our script to the printer, (pipe the finished PostScript document to the printer on port 9100) eliminating the stop off at the browser.  And, we can position things on our page with as much precision as necessary.


PHP has a basic set of functions for creating PostScript documents - and we're very grateful for this because it meant we didn't have to learn PostScript itself - but it lacks advanced text handling features such as vertical alignment and automatic resizing of text.  And, while it can do justified text, it does it in very mysterious ways.  Fortunately, these issues were not a problem for Mango, and Mango's PostScript Functions were born.

Here's the source to Mango's PostScript Functions including ps_super_boxed, a demo of how to vertically align and dynamically resize text with PHP and pslib, and the results of the demo, converted to PDF for easy viewing.  (One note: the demo requires the font file Helvetica.afm and we're not sure if we're allowed to distribute that, but it's very easy to find with Google.)

Enjoy!
 

If you would like a reply to your comment, you must leave your email address! We receive dozens of questions every month from people who don't leave us with any way to contact them, so we have no choice but to ignore the question. We try to reply to as many questions as we can, if we know the email address of the person who asked the question. Thanks in advance for writing in :)

Allowed HTML: <b>, <i>, <em>, <strong>. All other < and > will be replaced with &lt; and &gt;.