Direct Printing for Laravel Apps
Published on by Paul Redmond
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 printersPrinting::printers(); // Find a specific printerPrinting::find($printerId); // Getting the configured default printer and printer IDPrinting::defaultPrinter();Printing::defaultPrinterId();
If you have a receipt printer you can print them with the provided ReceiptPrinter
class:
$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.
This package was submitted to our Laravel News Links section. Links is a place the community can post packages and tutorials around the Laravel ecosystem. Follow along on Twitter @LaravelLinks