Page 1 of 1
Printing from the server with PHP
Posted: Fri Dec 22, 2006 8:36 am
by sylver
I need to print labels from PHP on a printer connected to the server.
The server is a Windows XP box running apache and php 5. PHP printing functions would be ideal but I can't get the extension to work.
extension=php_printer.dll is enabled in the php.ini file and the dll is in the correct folder, but I keep getting error messages that "printer_open()" is undefined.
Considering the links to the printer dll in the php manual are dead and that XP is not part of the supported OSes, I guess I have to find another way.
Due to the nature of the application, I need to print only one label at a time, so it would be a pain to pop up a printer selection dialog using javascript.
Is there another way to print directly from PHP?
Or if not, is it possible to call an external application and feed it the data to print?
Any help is more than welcome.
Posted: Fri Dec 22, 2006 9:12 am
by volka
sylver wrote:Considering the links to the printer dll in the php manual are dead
http://de2.php.net/manual/en/function.printer-open.php works fine for me.
Did you alter the right php.ini? phpinfo() can tell you. You have to restart the webserver if php is installed as module.
Posted: Fri Dec 22, 2006 10:58 am
by Kieran Huggins
I think he means the links to the appropriate PECL repo for the printer.dll PECL file.
I checked
http://pecl.php.net/packages.php and it's GONZO
I use 2 methods for printing: CSS || PDF (I know). PDF is the best for labels, as you don't need to worry about setting the margins in your printer settings. It's more work than it should be, but doable.
Cheers,
Kieran
Posted: Fri Dec 22, 2006 12:14 pm
by sylver
Kieran Huggins wrote:I think he means the links to the appropriate PECL repo for the printer.dll PECL file.
I checked
http://pecl.php.net/packages.php and it's GONZO
I use 2 methods for printing: CSS || PDF (I know). PDF is the best for labels, as you don't need to worry about setting the margins in your printer settings. It's more work than it should be, but doable.
Cheers,
Kieran
Thanks for the reply. I did consider PDF, but my problem is "how to print". Is there a way to print a PDF file in the background using PHP?
Let's say I get a PDF file with the label on, with the right page sizes and margin and everything...cool but how do I print it? I can't ask the user to click on "Print", select the printer and print... for each label.
I need to provide the user with a button which he can click on and the label prints out right away. Well at least, that's the idea
Posted: Fri Dec 22, 2006 12:30 pm
by Kieran Huggins
Maybe you could write the PDF to the filesystem and use shell_exec() to get Adobe Reader to print it?
I've never done this, as my users must obey my lazy ways

Let me know if it works!
Cheers,
Kieran
Posted: Fri Dec 22, 2006 1:03 pm
by John Cartwright
sylver wrote:Kieran Huggins wrote:I think he means the links to the appropriate PECL repo for the printer.dll PECL file.
I checked
http://pecl.php.net/packages.php and it's GONZO
I use 2 methods for printing: CSS || PDF (I know). PDF is the best for labels, as you don't need to worry about setting the margins in your printer settings. It's more work than it should be, but doable.
Cheers,
Kieran
Thanks for the reply. I did consider PDF, but my problem is "how to print". Is there a way to print a PDF file in the background using PHP?
Let's say I get a PDF file with the label on, with the right page sizes and margin and everything...cool but how do I print it? I can't ask the user to click on "Print", select the printer and print... for each label.
I need to provide the user with a button which he can click on and the label prints out right away. Well at least, that's the idea
Search
PDF auto print 
Posted: Sat Dec 23, 2006 12:59 am
by sylver
Jcart wrote:sylver wrote:Kieran Huggins wrote:I think he means the links to the appropriate PECL repo for the printer.dll PECL file.
I checked
http://pecl.php.net/packages.php and it's GONZO
I use 2 methods for printing: CSS || PDF (I know). PDF is the best for labels, as you don't need to worry about setting the margins in your printer settings. It's more work than it should be, but doable.
Cheers,
Kieran
Thanks for the reply. I did consider PDF, but my problem is "how to print". Is there a way to print a PDF file in the background using PHP?
Let's say I get a PDF file with the label on, with the right page sizes and margin and everything...cool but how do I print it? I can't ask the user to click on "Print", select the printer and print... for each label.
I need to provide the user with a button which he can click on and the label prints out right away. Well at least, that's the idea
Search
PDF auto print 
The idea of autoprint is interesting, but I don't see a solution in the search results. Sorry if it sounds stupid, but can you point out which exact website explain how to do this?
The first URL for that search contains 4 posts of guys who have the same question, but no solution, and the other urls seem either irrelevant or offer shareware to do the job.
Posted: Sat Dec 23, 2006 2:55 am
by sylver
Kieran Huggins wrote:Maybe you could write the PDF to the filesystem and use shell_exec() to get Adobe Reader to print it?
I've never done this, as my users must obey my lazy ways

Let me know if it works!
Cheers,
Kieran
Sounds interesting but I know next to nothing about the command line. Would you have simple explanations or point me in the right direction?
Posted: Sat Dec 23, 2006 11:57 am
by Kieran Huggins
I don't even know if it's possible to print a pdf from the command line, so I don't have any code for you
I have a
hunch that it's
likely though!
Either use Google or Adobe Reader's help file to find out what the command-line arguments are, there is likely one to print a file... it might look something like:
Again, I really have no idea, but that's what you could look for.
Cheers,
Kieran