LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   PHP: print directly from php script (https://www.linuxquestions.org/questions/linux-software-2/php-print-directly-from-php-script-704761/)

Zelrond 02-15-2009 03:09 AM

PHP: print directly from php script
 
Hi all, I didn't want bother you but I'm in trouble... deep in trouble. I "must" create a function, in my php application, to allow continuos print. I mean that it should send to printer "directly" some letters (changing names and addresses ;-) of course). I used javascript function "window.print()" but it wait for a button pressed from the
user...
Can anybody help me ?
Thanks.

jlinkels 02-16-2009 02:27 AM

Do you mean the client has to have a print function? The one who is browsing? Since you are using Javascript, this runs only client side.

The print function without acknowledge has intentionally been left out of clients to make sure the web designer would not be able to print tons of paper for his fun, therefor a user acknowledge is always needed.

But you are talking about PHP application. Do you mean you have to print on the server side?

jlinkels

Zelrond 02-16-2009 04:59 PM

Well, I wrote an application: I mean that the server is not "an internet" server: it's in the same room where clients are. In this case server's printer is THE client's printer (that printer is shared through the network).

jlinkels 02-16-2009 05:52 PM

That doesn't answer the question. Does the client print (Internet Explorer, Mozilla) or does the server print (Apache)? Regardless of where the printer is, regardless to what is is attached.

I have the idea that it is the client which prints, but if it is the client, how could PHP help you. PHP puts together the web page for you, and can do a zillion other things, but always on the server.

jlinkels

Zelrond 02-18-2009 04:50 AM

Thank you.
Now I can see that my question was wrong. Maybe the right question could be: How can I ask to PHP to print on default printer of the server?
In my case it's ok, because the server's printer is the printer (the only one) that anybody can use.
From network point of view it's always the same printer, but I understand that from php point of view it's not the same.
Regards.

jlinkels 02-18-2009 05:41 PM

Quote:

Originally Posted by Zelrond (Post 3448079)
Thank you.
From network point of view it's always the same printer, but I understand that from php point of view it's not the same.
Regards.

PHP runs on the server, so for PHP is is also the same printer.

Is it a Windows platform which runs the server? Then look at the print_open and print_write functions.

For Linux it is more difficult. Almost as difficult as creating a graph or a PDF file. I would recommend to open a temporary file, put the print data in there, and use an exec call to send it to lp.

To get rid of the temporary file, call a cleanup function every time the web page is entered, which deletes all temporary files older than 5 minutes.

http://www.linuxquestions.org/questi...nd#post3415608

jlinkels

servat78 02-18-2009 06:43 PM

Your PHP script will need to create printable pages first, most often in PostScript or PDF format. Libharu is pdf development library that you could use to create a CGI application for the task of creating a printable document. Pslib does the same for PostScript. PostScript is old, but has the advantage that it is for the larger part human-readable.

Your PHP script can either create PS/PDF files directly or call some other custom CGI application via a 'system' call, and then feed that document to the printer with a system call to 'lp' (see http://www.faqs.org/docs/Linux-HOWTO...age-HOWTO.html).

Printing will be done on any of the printers that are available to the server.

Debian

adeeriswan 12-06-2009 10:35 AM

Does this problem solved?
 
@Zelrond : Does this problem solved?

I'm also have this problems. I was to created a simple queue app, just for locally (LAN) so the server need to print a receipt (which contains the queue number) directly..

@jlinkels : if you don't mind, would u show us an example of it?

I'm really a newbie on PHP (i used to VB).

Thanx brother, I'll appreciate ur help


All times are GMT -5. The time now is 10:38 PM.