Direct Printing for Laravel Apps

Direct Printing for Laravel Apps

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 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

Filed in: News / packages

Newsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Laravel Developer
Remote
FPV Exchange
Senior Full-Stack Developer
Remote, USA Only
Givebutter
Senior PHP Developer
Cary, NC
INE
Backend PHP Developer
Hamburg
ABOUT YOU GmbH
Engineering Director
Vancouver or remote (EST/PST preferred)
Engine Digital