I have been all over stack looking at what is required to do this and have wound up being slightly confused.
Lets get one thing straight this is a local based intra-net and I do understand that PHP is server side.
I am running a company management solution on a web based PHP,JAVA,Jquery Idea. and we would like to print reports directly from the "LINUX" server and receipts etc.
I have installed cups on the server and the server is printing fine and I am now just stuck on whether or not it is actually possible to get the server to print our pdf files we are generating directly from the PHP code.
I would be happy even if we had a bash script to run and check a directory print the pdf and then delete it, even though I would see this as a work around for the time being.
Like I said I do understand that if this was done on the WWW then there would be certain exploits that could be used. If I were to run this system on the www I would have a totally different site that did not allow printing and this function would not be necessary.
Thank You in advance
Alex
If CUPS is configured properly, printing a PDF from the shell is literally as easy as
So, once you have written your PDF to a temporary file, you can use any of the available PHP functions to execute that shell command:
exec()
,shell_exec()
,system()
You could even do it without writing a temporary file and feed the data directly to
lpr
via STDIN (trycat myfile.pdf | lpr
as an example on the shell).You can feed data to a program's STDIN in PHP if you run it using
proc_open()
. The first example from the PHP Manual can be adapted to something like this:Use PHP::PRINT::IPP
It is the most secure and easiest way for printing from Web using PHP. Here you don't have to enable exploitable php functions like
exec()
,shell_exec()
etc.Basic Usage
Reference
Judicious use of php's
shell_exec()
should allow you to print PDFs synchronously, immediately after their creation, thus avoiding the need for bash.I've not used
shell_exec()
for printing so can't help with the detail but essentially, if you can successfully compose a UNIX print command, then you can write theshell_exec()
instruction.