Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printer_open() to print a html output

Tags:

html

php

With printer_open() function in php, I am able to print the string that I saved in $content variable, and able to 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 have a html output that I generated from the database, and is showing in the webpage, I need to print that directly to the printed in the same format once the page loads, I tried a lot but I dont know what I should do to make the printer to print directly the same HTML output once the page loads using the printer_open().

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


UPDATED

I dont want to use windows.print() method of javascript, since it shows the print dialogue box instead of initiating the printing job directly to the printer

I want users to hit submit form and printer to print the receipt directly without asking them anything

like image 730
Rahul TS Avatar asked Aug 08 '13 05:08

Rahul TS


1 Answers

You can try to use 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();
like image 162
Makc Avatar answered Oct 19 '22 23:10

Makc