I am trying to print pages pragmatically using a PHP script on an office printer.
Here is what I have so far:
I have a printer installed on the server, and I can send jobs to it using PHP using the command line command. I can also write text files with my PHP script and then add them to the cue. Thus, printing PHP generates simple text files with PHP working just fine.
The question is, how can I create printable files using PHP, which actually include 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, this is what I want to tear from the printer. In addition, it should work in a system without a GUI and without user intervention.
So far I have had the following possible ideas:
Use the PDF library PDF to create a PDF file and add it to the print type (it is very difficult to get the right positioning)
Use the GD library to create an image file (merging images and text into one image with page size) and send the final image to the printer.
Both of the above are complex, although they will be tedious to implement and support. I am wondering if there could be a simpler solution? Highlighting a page using html and CSS would be the easiest option. Is there a library or script that can create a PDF file from the displayed page from raw html / css markup?
Or is there a way to start firefox (or another browser) only in command line mode, but has full rendering capabilities that can be sent to a PDF or printer?
The long-running question is short - I'm looking for a way to send the displayed html / css page to the printer ...
Any ideas?
source share