I'm developing a POS system using Laravel Framework 9.52.16 In this system, I have stored all printers in the system and each printer is assigned to restaurant items. When they print the order to the kitchen I need to send it directly to each printer without popping anything. For that, I'm using \Mike42\Escpos\Printer package.
use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;
use Mike42\Escpos\Printer as EscposPrinter;
use Spatie\Browsershot\Browsershot;
foreach ($itemsByPrinter as $printerId => $items) {
$printer = PrinterConnection::find($printerId);
if ($printer) {
try {
$this->data['items'] = $items;
$htmlContent = view('admin.orders.test_print_order_for_kitchen', $this->data)->render();
$pdf = PDF::loadHTML($htmlContent);
$pdf->save(storage_path('app/test_print_order_for_kitchen.pdf'));
$imagePath = storage_path('app/test_print_order_for_kitchen.png');
Browsershot::html(view('admin.orders.test_print_order_for_kitchen', $this->data)->render())->save($imagePath);
$connector = new NetworkPrintConnector($printer->ip_address);
$printer = new \Mike42\Escpos\Printer($connector);
$printer->bitImage($imagePath);
$printer->cut();
} catch (Exception $e) {
echo "Couldn't print to this printer: " . $e->getMessage() . "\n";
}
} else {
echo "Couldn't find printer";
}
}
when I save as pdf its save properly
$pdf->save(storage_path('app/test_print_order_for_kitchen.pdf'));
when I try this way
$this->data['items'] = $items;
$htmlContent = view('admin.orders.test_print_order_for_kitchen', $this->data)->render();
$pdf = PDF::loadHTML($htmlContent);
$pdfFilePath = storage_path('app/test_print_order_for_kitchen.pdf');
$pdf->save($pdfFilePath);
$connector = new NetworkPrintConnector($printer->ip_address);
$printer = new Printer($connector);
$pdfContent = file_get_contents($pdfFilePath);
$printer->text($pdfContent);
this is working but the print is not correct
when I try this
$this->data['items'] = $items;
$htmlContent = view('admin.orders.test_print_order_for_kitchen', $this->data)->render();
$pdf = PDF::loadHTML($htmlContent);
$pdf->save(storage_path('app/test_print_order_for_kitchen.pdf'));
$imagePath = storage_path('app/test_print_order_for_kitchen.png');
Browsershot::html(view('admin.orders.test_print_order_for_kitchen', $this->data)->render())->save($imagePath);
$connector = new NetworkPrintConnector($printer->ip_address);
$printer = new \Mike42\Escpos\Printer($connector);
$printer->bitImage($imagePath);
$printer->cut();
I'm getting error
The command \"node \"C:\\xampp\\htdocs\\pos\\vendor\\spatie\\browsershot\\src/../bin/browser.cjs\" \"{\"\"url\"\":\"\"file:\\/\\/C:\\\\Users\\\\dell\\\\AppData\\\\Local\\\\Temp\\\\517914863-0313514001713855616\\\\index.html\"\",\"\"action\"\":\"\"screenshot\"\",\"\"options\"\":{\"\"type\"\":\"\"png\"\",\"\"path\"\":\"\"C:\\\\xampp\\\\htdocs\\\\pos\\\\storage\\\\app\\/test_print_order_for_kitchen.png\"\",\"\"args\"\":[],\"\"viewport\"\":{\"\"width\"\":800,\"\"height\"\":600},\"\"displayHeaderFooter\"\":false}}\"\" failed.\n\nExit Code: 1(General error)\n\nWorking directory: C:\\xampp\\htdocs\\pos\\public\n\nOutput:\n================\n\n\nError Output:\n================\n'node' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n
I did so many changes to correct this. Node and everything installed`
If anyone can help me to do this.
I want to print each item assign printer like this
