954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How To Print Directly to Printer

Hi all,

How can we gain control of printer using php? I mean gain control as in, choosing the right printer from our php page and send the document directly to printer. I want to bypass the print dialog box that will appear when we print from web browser.

By the way, I've checked the PHP.net to check on printer functions ( http://my.php.net/manual/en/ref.printer.php ), it contains outdated links. I am really not sure how to get about using the function. I've already tried to download the php_printer.dll file from some website and unquote the extension in the php.ini file but can't get the printer_open() function to work, Perhaps someone can point to me where to download the right file or the right steps to do in order to use it .

I know we can't do this with Javascript, or can we?

Really appreciate all the info i can get. Thanks

chunguy
Newbie Poster
24 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

I don't believe this is possible as PHP is a scripting language, and therefore doesn't have the ability to gain control of hardware directly. For example, you wouldn't be very happy if you were surfing the web and various PHP-driven sites had direct access to your hard drive and hardware! What you're looking for should be possible through ActiveX controls. ActiveX controls are mini-programs (??) that are downloaded automatically over the Internet ... such as the way that the Windows Update website has control to install software to your hard drive automatically. Not sure how they work though ... that's a Microsoft thing.

cscgal
The Queen of DaniWeb
Administrator
19,429 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
 

hi hi,

well, i think i;ll explain the scenario that i'm in. i'm doing a system whereby the client PC will request to print a list, and the list is of course sent to the server. On the server, it will analyze the list and dispatch the list to the correct orinter to print. Or maybe dispatching the list to several printers that I pre-set.

I want all of this to be done without the client PC having to select which printer to print to. Thus, I don't want the print dialog window to appear on the client PC.

chunguy
Newbie Poster
24 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

I'm not sure if there is a way to send files to the printer without the user's consent. That would be like hacking the enduser. The best you can do, from what I know so far, is that you can use Javascript to show the print dialog on a page (you can easily find the code for this online.)

Gary King
PHP/vBulletin Guru
Team Colleague
417 posts since Nov 2003
Reputation Points: 53
Solved Threads: 5
 

no,definitely not hacking. All I want is just this. The user on the client PC will click on a print button and the content of the page/form will be sent back to the server. The server will then dispatch the content to the appropriate printer. I just want to eliminate the step where the user needs to use the print dialog box. By the way, i need this for to do a web based application.

chunguy
Newbie Poster
24 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

I didn't suggest that you were hacking, but this SOUNDS like it. What I mean is that, since it seems like hacking, I don't think it can be done. But I'm sure you can do it in a similiar method.

Gary King
PHP/vBulletin Guru
Team Colleague
417 posts since Nov 2003
Reputation Points: 53
Solved Threads: 5
 

thanks gary for your comments. don't worry, I wasn't offended by the hacking issue. I just want a solution to this problem. Thought perhaps there's someone out there who had come across this problem and had a way to get aound it.

Thanks anyway.

chunguy
Newbie Poster
24 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

I guess the very first issue here is, PHP will be installed in your server. And there might be 2 issue, one is using WIN OS, and the other might be unix based os.
I know you can make use of LINUX command in PHP to trigger the printing. You can alos use normal DOS COMMANF in PHP if you are running WIN OS. It is simply the lineprint command or copy to lpt port. but I wouldn't know how can you track with the NETWORK Printer is ready, and able to print. Hope this does help. regarding the phpprinter command, it is only able to run in WINDOWS environment.

xiaolee
Newbie Poster
1 post since Feb 2005
Reputation Points: 10
Solved Threads: 0
 
PoA
Posting Whiz in Training
237 posts since Jul 2004
Reputation Points: 26
Solved Threads: 9
 
I hope this would help you http://docs.php.net/en/ref.printer.html


that has already been posted

Please next time read THE VERY FIRST POST

Gary King
PHP/vBulletin Guru
Team Colleague
417 posts since Nov 2003
Reputation Points: 53
Solved Threads: 5
 
I guess the very first issue here is, PHP will be installed in your server. And there might be 2 issue, one is using WIN OS, and the other might be unix based os. I know you can make use of LINUX command in PHP to trigger the printing. You can alos use normal DOS COMMANF in PHP if you are running WIN OS. It is simply the lineprint command or copy to lpt port. but I wouldn't know how can you track with the NETWORK Printer is ready, and able to print. Hope this does help. regarding the phpprinter command, it is only able to run in WINDOWS environment.

can you elaborate a bit more of the how to lineprint to copy to lpt port ? pardon me for my ignorance.

btw, POA i'm running win XP, it seems that the functions listed there does not support win xp... although someone posted on the user contribution that it can actually be used on XP too. tried email-ing the person but to no response. http://my.php.net/manual/en/ref.printer.php

chunguy
Newbie Poster
24 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

Say after me: you can not access hardware on the client machine from a serverside application or script.

You CAN print from your serverside application to any printer which is attached to the server (if PHP supports that...), but never to the client.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Oh yes you can...

Of course PHP can print to a printer linked to the server. It's called an intranet! Most PHP is coded as internal utilities within companies... not on external websites. Try the PECL php_printer.dll install and then use the print functions. On Unix just do a system('lpr')...

gmalcolm
Newbie Poster
1 post since Apr 2005
Reputation Points: 10
Solved Threads: 0
 
I don't believe this is possible as PHP is a scripting language, and therefore doesn't have the ability to gain control of hardware directly. For example, you wouldn't be very happy if you were surfing the web and various PHP-driven sites had direct access to your hard drive and hardware! What you're looking for should be possible through ActiveX controls. ActiveX controls are mini-programs (??) that are downloaded automatically over the Internet ... such as the way that the Windows Update website has control to install software to your hard drive automatically. Not sure how they work though ... that's a Microsoft thing.



Visual basic can produce activex programs

stoopidnerd
Newbie Poster
2 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

you can print directly to a printer held on the clients machine. the php_printer.dll is needed which can be found in the PECL downloads.

once you have downloaded and copyed the php_printer.dll into your extensions folder i.e. c:\php\ext edit the php.inin in c:\php\ and add a line extension=php_printer.dll line in the extensions section, re start iis or apache webserver.

Check that the php extensions has loaded by creating a info.php file containing

<?php
phpinfo();
?>


scroll down for printer settings this will determine that the extensions is initialised correctly

Then on the php.net website do a search for printer_set_option for printer function and you will see all the printer fuctions that php has to offer.

psycho007
Newbie Poster
23 posts since Oct 2008
Reputation Points: 14
Solved Threads: 0
 

Hi I am faced with a similar problem where I'd like to eliminate the additional step of the print dialog box and have php select and sent the print job to the appropriate printer. I was wondering if anyone found a solution to this problem ...

Thank you for your help!

achunawala
Newbie Poster
1 post since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

Dear psycho007 ...
I want to ask u that this solution is for localhost or it can be functional over the linux server (online not on localhost)

sadaf786
Newbie Poster
1 post since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

hai friends ,
am doing standalone project by localhost(client & server inthe same machine),i need to print the content from the database to printer continously (billing process).printer is dotmatrix printer,how to print one record print in the onesheet and another record print in next sheet ,am using [php ,mysql,javascript] language for code

thanking u,
J.JAGAN

jaha.j
Newbie Poster
1 post since Feb 2010
Reputation Points: 10
Solved Threads: 0
 
I don't believe this is possible as PHP is a scripting language, and therefore doesn't have the ability to gain control of hardware directly. For example, you wouldn't be very happy if you were surfing the web and various PHP-driven sites had direct access to your hard drive and hardware! What you're looking for should be possible through ActiveX controls. ActiveX controls are mini-programs (??) that are downloaded automatically over the Internet ... such as the way that the Windows Update website has control to install software to your hard drive automatically. Not sure how they work though ... that's a Microsoft thing.

This is the mechanism that allows IE to infect computer with viruses.

aaln
Newbie Poster
8 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

I'm sorry to bump this thread.

I've done an application that can print to a client on LAN. It is a barcode labeling system that has maximum of 4 clients that do the printing, and few others that handles data.

you can actually open a network printer via this:

printer_open("\\\\client.ip.address\\sharename");


and send printer commands to it given these requirements:

1. apache (php on apache) is run by a normal user that has network privilege and has access to the lan printer. (To make it complicated, I set that user's username and password available to every client that has printing job. That is because Windows XP SOMETIMES denies access to shared resource whatever permission you set.)

2. php printer extension is installed.

Of course the server must know where to print. I've done this by having a printer database for each client along with the printer share name.

Our application has been running already a year.

PS: It is error prone (network / windows issues)

lysender
Newbie Poster
3 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You