Printing from the server with PHP
Moderator: General Moderators
Printing from the server with PHP
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.
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.
sylver wrote:Considering the links to the printer dll in the php manual are dead
Did you alter the right php.ini? phpinfo() can tell you. You have to restart the webserver if php is installed as module.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
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
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?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
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
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Search PDF auto printsylver wrote: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?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
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
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?Jcart wrote:Search PDF auto printsylver wrote: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?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
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
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.
Sounds interesting but I know next to nothing about the command line. Would you have simple explanations or point me in the right direction?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 waysLet me know if it works!
Cheers,
Kieran
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
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
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'Cheers,
Kieran