Laravel Printing is a package by Randall Wilk that allows your web application to send PDF documents or raw text from a remote server to a printer on your local network.
At the time of writing this package supports a PrintNode driver (with others planned) to power the communication between your web application and printers. If your mind is still trying to make sense of how this works, here’s an example of how the code looks:
$printJob = Printing::newPrintTask() ->printer($printerId) ->file('path_to_file.pdf') ->send(); // the id number returned from the print server $printJob->id();
Here are some cool things you can do with this package:
// List all printers Printing::printers(); // Find a specific printer Printing::find($printerId); // Getting the configured default printer and printer ID Printing::defaultPrinter(); Printing::defaultPrinterId();
If you have a receipt printer you can print them with the provided
$text = (string) (new ReceiptPrinter) ->centerAlign() ->text('My heading') ->leftAlign() ->line() ->twoColumnText('Item 1', '2.00') ->twoColumnText('Item 2', '4.00') ->feed(2) ->centerAlign() ->barcode('1234') ->cut(); Printing::newPrintTask() ->printer($printerId) ->content($text) // content will be base64_encoded if using PrintNode ->send();
You can learn more about this package, get full installation instructions, and view the source code on GitHub at rawilk/laravel-printing.