Printing from the server with PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sylver
Forum Newbie
Posts: 4
Joined: Fri Dec 22, 2006 7:37 am

Printing from the server with PHP

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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 8O

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
sylver
Forum Newbie
Posts: 4
Joined: Fri Dec 22, 2006 7:37 am

Post 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 8O

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
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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 8O

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 ;)
sylver
Forum Newbie
Posts: 4
Joined: Fri Dec 22, 2006 7:37 am

Post 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 8O

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.
sylver
Forum Newbie
Posts: 4
Joined: Fri Dec 22, 2006 7:37 am

Post 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?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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:

Code: Select all

reader.exe /p 'path\to\file.pdf'
Again, I really have no idea, but that's what you could look for.

Cheers,
Kieran
Post Reply