LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 02-15-2009, 03:09 AM   #1
Zelrond
LQ Newbie
 
Registered: Feb 2009
Distribution: ubuntu 8.10
Posts: 3

Rep: Reputation: 0
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.
 
Old 02-16-2009, 02:27 AM   #2
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,103

Rep: Reputation: 494Reputation: 494Reputation: 494Reputation: 494Reputation: 494
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
 
Old 02-16-2009, 04:59 PM   #3
Zelrond
LQ Newbie
 
Registered: Feb 2009
Distribution: ubuntu 8.10
Posts: 3

Original Poster
Rep: Reputation: 0
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).
 
Old 02-16-2009, 05:52 PM   #4
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,103

Rep: Reputation: 494Reputation: 494Reputation: 494Reputation: 494Reputation: 494
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
 
Old 02-18-2009, 04:50 AM   #5
Zelrond
LQ Newbie
 
Registered: Feb 2009
Distribution: ubuntu 8.10
Posts: 3

Original Poster
Rep: Reputation: 0
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.

Last edited by Zelrond; 02-18-2009 at 04:53 AM.
 
Old 02-18-2009, 05:41 PM   #6
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,103

Rep: Reputation: 494Reputation: 494Reputation: 494Reputation: 494Reputation: 494
Quote:
Originally Posted by Zelrond View Post
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
 
Old 02-18-2009, 06:43 PM   #7
servat78
Member
 
Registered: Jan 2009
Posts: 100

Rep: Reputation: 17
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

Last edited by servat78; 02-19-2009 at 11:34 AM.
 
Old 12-06-2009, 10:35 AM   #8
adeeriswan
LQ Newbie
 
Registered: Dec 2009
Location: Jakarta
Distribution: Ubuntu, Fedora
Posts: 1

Rep: Reputation: 0
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

Last edited by adeeriswan; 12-06-2009 at 10:39 AM.
 
  


Reply

Tags
php, print


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
php/shell script to install mysql,apache and php automatically stranger_6_7 Linux - General 2 08-11-2009 02:07 AM
You have chosen to open index.php which is a : PHP Script from: http://localhost cucolin@ Linux - Software 3 01-30-2007 03:58 PM
Adding users with PHP (pass php variables to Expect script) Jayla Programming 1 10-20-2006 10:44 AM
LXer: Title: PHP/MySQL Classifieds Script AddAsset1.php Script Insertion LXer Syndicated Linux News 0 07-02-2006 06:21 PM
PHP -- How to execute a shell script from PHP using FTP functions?? zoonalex Programming 3 07-29-2004 11:51 AM


All times are GMT -5. The time now is 07:00 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration