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:
1$printJob = Printing::newPrintTask()2 ->printer($printerId)3 ->file('path_to_file.pdf')4 ->send();5 6// the id number returned from the print server7$printJob->id();
Here are some cool things you can do with this package:
1// List all printers2Printing::printers();3 4// Find a specific printer5Printing::find($printerId);6 7// Getting the configured default printer and printer ID8Printing::defaultPrinter();9Printing::defaultPrinterId();
If you have a receipt printer you can print them with the provided ReceiptPrinter
class:
1$text = (string) (new ReceiptPrinter) 2 ->centerAlign() 3 ->text('My heading') 4 ->leftAlign() 5 ->line() 6 ->twoColumnText('Item 1', '2.00') 7 ->twoColumnText('Item 2', '4.00') 8 ->feed(2) 9 ->centerAlign()10 ->barcode('1234')11 ->cut();1213Printing::newPrintTask()14 ->printer($printerId)15 ->content($text) // content will be base64_encoded if using PrintNode16 ->send();
You can learn more about this package, get full installation instructions, and view the source code on GitHub at rawilk/laravel-printing.
0 comments:
Post a Comment
Thanks