Link to home
Start Free TrialLog in
Avatar of ronipats
ronipats

asked on

HOw to send print job to printer directly from php page without preview

Hi all,

i am developing a bill application in php, mysql.
I have designed and developed bill.php form in which, on pressing print button, i want to print the bill to printer.

I have designed onw bill report in using fpdf. so the format of bill is .pdf.

Now each time i press on print button, bill.pdf file is getting previewed and then only i am able to take print out of it.

What i want to do is, i want to print that bill to printer without generating preview, or opening any sort of popup window. Again it should be fast enough.

How can i do that.

Any solution other than fpdf is there, then also it is welcomed.
ASKER CERTIFIED SOLUTION
Avatar of duncanb7
duncanb7

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dave Baldwin
I don't believe you can do that.  PHP running on the server does not have access to a user's printer (though it might be able to print to a printer connected to the server).  Even when you have generated the PDF, you still have to send it to the user.  When a user prints a document, it will have to print from a file on their computer.  

While most browsers have a way to open a PDF these days, you can not force it to be printed.  It is one of the basic security restrictions in all browsers is that you can not force anything to be done on the user's computer.  They have to be able to approve anything you want to do on their machine.  That includes printing and downloading and uploading files.
You're on firm ground by using FPDF.  There is also TCPDF, but I don't think the choice of PDF generation software matters.  

The question seems to evince some confusion about the roles of the client and the server.  These are terms of art in modern computer design.  More information is available here:
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/A_11271-Understanding-Client-Server-Protocols-and-Web-Applications.html

The server can respond to a client request by sending a document, but it cannot initiate an action on the client machine.  In other words, if your clients are using the internet to talk to your server, then the clients have to be the ones that tell the browser to print the document.  However if you're using a networked printer on Windows, you may be in luck.

Please see http://www.php.net/manual/en/printer.installation.php

It's a windows-only extension that is intended to make a networked printer do things.  In other words, it does not work over the internet and support may be spotty or release dependent.
Avatar of duncanb7
duncanb7

Thanks for your points

Have a nice day

Duncan