I'm trying to print pages pragmatically with a PHP script, to an office printer.
Here's what I've got so far:
I have a printer installed on the server, and I can send jobs to it with PHP via the command line's print command. I can also write plain text files with my PHP script, and then add them to the print cue. So printing PHP generated plain text files with PHP works just fine.
The question is, how can I create printable files, using PHP, that actually incorporate layout and graphics? In other words, if I created a web page with images and css, and then displayed the page in Firefox, and clicked print, that's what I want to come off the printer. Except it needs to work on a system without a GUI, and without user intervention.
So far I have these possible ideas:
Use a PHP PDF library to generate a PDF file and add that to the print cue (very complicated to get the positioning right)
Use the GD library to generate an image file (merging images and text into one page-sized image), and sending the final image to the printer.
Both of the above are complicated though, and would be tedious to implement and maintain. I'm wondering if there might be a simpler solution? Laying out the page using html and CSS would be the easiest option. Is there a library or script that can produce a PDF of a rendered page from raw html/css markup?
Or a way to run firefox (or another browser) in command line only mode, but has full rendering capabilities that could be sent to a pdf file or the printer?
Long question short- I'm looking for a way to send a rendered html/css page to a printer...
Any ideas?