moodsey211 0 Report post Posted July 10, 2008 I'm making a site which generates a number of reports. I want to print it to the user's printer. Any idea how can I obtain this.Thanks in advance. Share this post Link to post Share on other sites
truefusion 3 Report post Posted July 10, 2008 PHP is for server side scripting, not client side. In order to achieve this, you're going to need java script: window.print() Share this post Link to post Share on other sites
moodsey211 0 Report post Posted July 10, 2008 Yes, that's really one of my concerns so I'm collecting ideas on how to go around it. the javascript print function is very primitive and it shows a dialog box before printing. need something to go around this. Share this post Link to post Share on other sites
truefusion 3 Report post Posted July 10, 2008 If the dialog box is the same one when you hit Ctrl+P on the keyboard (which i'm sure it is), then it is best if left that way. This allows users to pick the printer they want if they have more than one printer to choose from and it also allows them to modify the page margins, how many pages they want to print, etc. Share this post Link to post Share on other sites
moodsey211 0 Report post Posted July 11, 2008 I have two options to choose from. one is to connect to the client using a socket, or let the browser call my application. But both needs the client to install my app on their machines which has less security issues. my problem is which of the two would i choose. Share this post Link to post Share on other sites
truefusion 3 Report post Posted July 11, 2008 I'd go with the browser call, assuming the client can still print offline. But i am left wondering, what is the purpose of PHP here, then, if it's more related to a desktop application? Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted July 11, 2008 One possibility might be to use the php functions to "write" a file for download and then have the client print it locally. Share this post Link to post Share on other sites
moodsey211 0 Report post Posted July 11, 2008 I was thinking of making php write a file and let the browser automatically call my app if ever it encounters the file created by php. But the action should be generated by php. or something like that. sounds wild. Share this post Link to post Share on other sites
raqib 0 Report post Posted July 11, 2008 as far as i know it is not possible in php. If possible pls somebody explain the procedure. Share this post Link to post Share on other sites
moodsey211 0 Report post Posted July 12, 2008 as far as i know it is not possible in php. If possible pls somebody explain the procedure.its possible. but you need to install something on the clients machine to be able to print to their printers. It's impossible to do it alone with just a server side script. Share this post Link to post Share on other sites
iGuest 3 Report post Posted December 9, 2008 Â you can use this code: <form><input type="button" value="Print This Page" onClick="window.Print()" /></form>-reply by msdivie Share this post Link to post Share on other sites
iGuest 3 Report post Posted April 30, 2009 its possible. But you need to install something on the clients machineTo be able to print to their printers. It's impossible to do it aloneWith just a server side script.  moodsey211, you cannot install something on the users machine, it is not user friendly and also, the application of that is not legal, cause then anyone can install malware via server side code. -reply by Skovoski Share this post Link to post Share on other sites
k_nitin_r 8 Report post Posted May 6, 2009 Yes, that's really one of my concerns so I'm collecting ideas on how to go around it. the javascript print function is very primitive and it shows a dialog box before printing. need something to go around this. If you do not wish to show the print dialog box, then you would need a Java applet or an ActiveX control - a signed applet or control can do quite a bit outside the security sandbox, making the browser little more than a mere container for a desktop application.You might want to stick with the idea of displaying a print dialog box because some people have multiple printers configured and they might want to have the option of selecting a printer.BTW, I think a desktop application is better suited for this situation - get the user to download an application that connects to the server via web services. That way, you can modify your existing PHP scripts to serve data to the client and use the client application to customize the print behavior to your liking.Regards,Nitin Share this post Link to post Share on other sites
contactskn 2 Report post Posted May 7, 2009 Dear friend I think you should generate a plain looking report and after being displayed in the browser it can be printed by using the print option of the browser. Other wise you should use java script to solve your problem if you want the report to be printed directly.? Share this post Link to post Share on other sites
iGuest 3 Report post Posted July 6, 2009 Just thought I'd put my two cents in on this. There is a free php library called fpdf, which you can use to make a pdf file that can be displayed on the screen. The user can then just print the pdf file with the browser. I use it in my web app for report generation. It works great. Check it out. Share this post Link to post Share on other sites