Printer_open () to output html output

With the printer_open() function in php, I can print the line that I saved in the $content variable and can print from a file.

 $printer = "\\\\Pserver.php.net\\printername"; $handler = printer_open($printer); $content = "Test Content"; //string printer_write($handler, $content); printer_close($handler); 

But I have the html output that I generated from the database and display on the web page, I need to print it directly to print in the same format, as soon as the page loads, I tried a lot, but I don’t know what I should do so that the printer printer_open() exact same HTML result immediately after loading the page using printer_open() .

What should I do? Please suggest a better method than this, if any.


UPDATED

I do not want to use the javascript method for windows.print (), since it displays a print dialog instead of initiating a print job directly to the printer

I want users to press the submit button and printer to print the receipt directly without asking for anything.

+8
html php
source share
3 answers

You can try using the output buffer:

 ob_start(); // generate your output from the DB here // ..... // Send generated output to the printer printer_write($handler, ob_get_contents()); // And show it to client on the frontend ob_end_flush(); 
+2
source share

create a hidden field with autofocus (requires a browser with HTML5 support) and start printing using the html onblur attribute (output if the user clicks any other form element) or the onfocus attribute on a specific form element (button). Do not submit the form because this will reload the page ....

0
source share

As far as I understand your question, you are trying to display HTML and then print it. Unfortunately, if you do it on the client side, you will need to print it on the client side, which initiates a print dialog. A.

You can run PhantomJS on the server to display the HTML, save the snapshot, and print it, but it sounds like a mass bust to print an invoice.

Probably the best idea would be to create a PDF file and print.

0
source share

All Articles