every time i close the bill I want it automatic print,

I write program with php, how  can it print invoice when customer make a payment , pres  bottom then it print with out any confirm and select printer, what is printer that work good i use windows 10,
teeraAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
do you think we should allow a computer via its web browser to use the printer without any confirmation from the user ?
I mean everyone browsing the web can see its printer delivering spams?

you can do this using third party plugins which ask user permission to install
An Average Forum Participant Just For FunHardware Tester and DebuggerCommented:
Have you tried printing on the local printer with something like this. It mentions to you all of the the printers first as I believe you were trying say that the list of printers connected may contain more than one printer. As for how you proceed, you might want to continue doing this for each loop to see if more than one is available or just take the first one in the list, like below.

<?php

ini_set('display_errors',1);
error_reporting(E_ALL);
	
$contents="Test print.";
eval("\$output = \"$contents\";");

$getprt=printer_list( PRINTER_ENUM_LOCAL | PRINTER_ENUM_SHARED );
$handle = printer_open(getprt['NAME']);
     if($handle)
          echo "connected";
     else
          echo "not connected";    
printer_set_option($handle, PRINTER_MODE, "raw"); 
printer_write($handle,$output);
printer_close($handle);
			
?>

Open in new window

teeraAuthor Commented:
Hi  An Average Forum Participant Just For Fun


( ! ) Parse error: syntax error, unexpected '[' in C:\wamp\www\test\print.php on line 10
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

An Average Forum Participant Just For FunHardware Tester and DebuggerCommented:
Hi!

Okay so in line 10, you might want to change the 'Name' to the actual name of the printer you want to auto-print.

For example:

$handle = printer_open(getprt['HP LaserJet 4350']);

Open in new window

teeraAuthor Commented:
it still show ( ! ) Parse error: syntax error, unexpected '[' in C:\wamp\www\test\print.php on line 10


<?php

ini_set('display_errors',1);
error_reporting(E_ALL);
	
$contents="Test print.";
eval("\$output = \"$contents\";");

$getprt=printer_list( PRINTER_ENUM_LOCAL | PRINTER_ENUM_SHARED );
$handle = printer_open(getprt['Canon MP230 series Printer']);
     if($handle)
          echo "connected";
     else
          echo "not connected";    
printer_set_option($handle, PRINTER_MODE, "raw"); 
printer_write($handle,$output);
printer_close($handle);
			
?>

Open in new window

An Average Forum Participant Just For FunHardware Tester and DebuggerCommented:
Okay before I tell you what I think is the problem, allow me to explain something.. A class of printers, often called network printers, are specifically designed for connecting directly to a computer network.  Is your station configured to adapt specifically or operate differently when connected to a certain network?? (e.g. at work, at school, at a government building)
Julian HansenCommented:
You can't do this with PHP!!!
PHP runs on the server - not the client - the suggestion above (assuming it works) will mean every time you print it will come out on a server attached printer -
Which
a) Is unlikely to exist
b) Even if it did is no use to anyone.
c) If you want this to print on the server then you are doing this the wrong way (refer note below)

Look at Leakim's answer

Control over the browser and local machine is specifically ring fenced for very obvious reasons. Code from the internet is toxic - always  - there is no such thing as a Safe site.

For this reason anything where a script must interact with browser settings or local machine is either
a) specifically prohibited
OR
b) Requires user action to authorise

Print button means print dialog.

If you want the printout to happen on the server side then the way you do that is with an external process that is either triggered by the script or runs as a cron job.
This process does not automatically print anything - it checks the database for records with a certain status and prints those.
This way the process controlling the printing is linked to the state of the data - not a request coming from the browser.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
teeraAuthor Commented:
IF I use JavaScript or another  language such as c#  it is possible to print with out confirm or not      incase I use c# How can i use php or javacript to triggered c# program
Julian HansenCommented:
Where do you want the print out to be printed?

On the client workstation
OR
The server
teeraAuthor Commented:
I prefer print in client
Julian HansenCommented:
Then as discussed - that is not possible.

C# won't help you nor will any other server-side language - because they run on the server they don't have any control of the client at all.

If you want to interact with the client then you use JavaScript - JavaScript will allow you to initiate a print of the page with window.print() but you cannot start the print job, nor can you select anything regarding the print job. Only the user can make the final printer selection and initiate the print.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 10

From novice to tech pro — start learning today.