Save Printer-content to file
Hi, recently I stumbled upon this great piece of software. Before that, I've printed receipts from a windows machine to an Epson printer so that I build the content wit ESC-codes and then automatically saved with a custom header and sent the saved file to com1 with a .bat file (copy %1 COM1)
Here a simplified example
header("Content-type: application/vnd.print");
header("Content-disposition: inline; filename=demo.prser");
header("Pragma: no-cache");
header("Expires: 0");
echo chr(27) . "@"; //Initializes the printer (ESC @)
echo chr(27) . "a" . chr(1);
//Specifies a centered printing position (ESC a)
echo chr(27) . "!" . chr(0); //Specifies font A (ESC !)
echo chr(27) . "!" . chr(17);//Selects double-height mode
echo chr(10) . "Hello" . chr(10);
echo chr(27) . "!" . chr(0);//Cancels double-height mode
echo chr(10) . chr(29) . "V" . chr(66) . chr(0); //Feeds paper & cut
Can I achieve the same with this library? Save the binary output locally with the header-commands.
For clarification: The software is on a server, the client uses a browser to print receipts. I can't use the PrintConnectors locally so I have to to save the binary output locally and send the binary output of the library cia copy %1 COM1 to the locally installed printer.
Maybe with the DummyPrintConnector. But i can't figure out how to retrieve the buffered data.
I have an possible solution, but maybe there's something better.
I save the binary output with the FilePrintConnector like
$connector = new \Mike42\Escpos\PrintConnectors\FilePrintConnector(__DIR__.'/print.prser');
After I finish with the library part I read this binary file and save it via header commands locally. In Windows I have an print.bat what send the data to the printer. I say I want alwas save .prser files and and open them with the print.bat command.
The last part looks something like that
header("Content-type: application/vnd.print");
header("Content-disposition: inline; filename=print.prser");
header("Pragma: no-cache");
header("Expires: 0");
$fp = fopen(__DIR__.'/print.prser', 'rb');
fpassthru($fp);
exit;
Now I have to test this and hope it's working. Maybe there is somewhere in the library some function I didn't found, that print's out the binary content si I could save it locally via the header-commands. I would appreciate it, if someone would point out such a function
We have a very similar example already tracked, for a Star cloud printer. You may be interested in checking it out: 235-get-data.php.
There are many other ways to send data from server to client, the FAQ entry Can I print from my server on the Internet? addresses some possible scenarios.