PHPackages                             xslain/laravel-printing - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. xslain/laravel-printing

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

xslain/laravel-printing
=======================

Direct printing for Laravel apps

2.0.0(9mo ago)069MITPHPPHP ^8.2

Since Sep 23Pushed 9mo agoCompare

[ Source](https://github.com/ogoungaemmanuel/printing)[ Packagist](https://packagist.org/packages/xslain/laravel-printing)[ Docs](https://github.com/xslain/laravel-printing)[ RSS](/packages/xslain-laravel-printing/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (15)Versions (3)Used By (0)

Laravel Printing Package - Network &amp; USB Printing
=====================================================

[](#laravel-printing-package---network--usb-printing)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ffed142f59ee68bd550822b804833eeb051b7893f1958288b03b4373c12d6927/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f78736c61696e2f6c61726176656c2d7072696e74696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/xslain/laravel-printing)[![Tests](https://github.com/xslain/laravel-printing/workflows/Tests/badge.svg?style=flat-square)](https://github.com/xslain/laravel-printing/workflows/Tests/badge.svg?style=flat-square)[![Total Downloads](https://camo.githubusercontent.com/9485d3366f61680f9462a173fece6fdcdbfe1726c8d0e3355abd4fa913844077/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f78736c61696e2f6c61726176656c2d7072696e74696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/xslain/laravel-printing)[![PHP from Packagist](https://camo.githubusercontent.com/c3afabdc283f3f8e06e181a0c450b927f773a1f2835854ed6037f02d3e6903bf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f78736c61696e2f6c61726176656c2d7072696e74696e673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/xslain/laravel-printing)[![License](https://camo.githubusercontent.com/5d4f23e2efc016ae6dc667e3b63facc2745b39791873a3ecdff014596c16803b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f78736c61696e2f6c61726176656c2d7072696e74696e673f7374796c653d666c61742d737175617265)](https://github.com/xslain/laravel-printing/blob/main/LICENSE.md)

[![social image](https://camo.githubusercontent.com/b4c36c7bada278f344fb6599b6aea5ccfc1dc59baaa2d0b3be6dd529f8778154/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f5072696e74696e67253230666f722532304c61726176656c2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d78736c61696e2532466c61726176656c2d7072696e74696e67267061747465726e3d7061726b6179466c6f6f72267374796c653d7374796c655f31266465736372697074696f6e3d4469726563742b7072696e74696e672b666f722b4c61726176656c2b617070732e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d7072696e746572)](https://camo.githubusercontent.com/b4c36c7bada278f344fb6599b6aea5ccfc1dc59baaa2d0b3be6dd529f8778154/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f5072696e74696e67253230666f722532304c61726176656c2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d78736c61696e2532466c61726176656c2d7072696e74696e67267061747465726e3d7061726b6179466c6f6f72267374796c653d7374796c655f31266465736372697074696f6e3d4469726563742b7072696e74696e672b666f722b4c61726176656c2b617070732e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d7072696e746572)

This Laravel package provides comprehensive printing capabilities including PDF generation, Excel/CSV import/export, download management, view printing, and **direct hardware printing via network and USB connections**.

Key Features
------------

[](#key-features)

- **Multiple Print Drivers**: PrintNode, CUPS, Network, USB, Raw
- **PDF Generation**: Convert HTML to PDF and print directly
- **View Printing**: Print Blade templates as PDFs or raw output
- **Network Printing**: Direct TCP/IP printing to network printers
- **USB Printing**: Direct communication with USB printers
- **Raw Printing**: Support for multiple connection types (network, USB, parallel, serial)
- **Excel/CSV Operations**: Import and export spreadsheet data
- **Download Management**: Create and manage file downloads
- **ESC/POS Support**: Thermal printer command support

```
// Network printing
$printJob = Printing::driver('network')
    ->newPrintTask()
    ->content('Hello Network Printer!')
    ->send();

// USB printing
$printJob = Printing::driver('usb')
    ->newPrintTask()
    ->content('Hello USB Printer!')
    ->send();

// View printing
$printJob = Printing::newPrintTask()
    ->view('printing.invoice', ['data' => $invoiceData])
    ->pdf(['format' => 'A4'])
    ->send();
```

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require xslain/laravel-printing
```

Publish the configuration file:

```
php artisan vendor:publish --tag="printing-config"
```

Publish the view templates (optional):

```
php artisan vendor:publish --tag="printing-views"
```

Quick Start
-----------

[](#quick-start)

### Environment Configuration

[](#environment-configuration)

Add to your `.env` file:

```
# Default driver
PRINTING_DRIVER=printnode

# PrintNode (cloud printing)
PRINTING_PRINTNODE_KEY=your_printnode_api_key

# Network printing
PRINTING_NETWORK_IP=192.168.1.100
PRINTING_NETWORK_PORT=9100

# USB printing
PRINTING_USB_DEVICE_PATH=/dev/usb/lp0
# OR
PRINTING_USB_VENDOR_ID=04b8
PRINTING_USB_PRODUCT_ID=0202
```

### Basic Usage

[](#basic-usage)

```
use Xslain\Printing\Facades\Printing;
use Xslain\Printing\Enums\PrintDriver;

// Print to default printer
$task = Printing::newPrintTask()
    ->content('Hello World!')
    ->send();

// Print via network
$task = Printing::driver(PrintDriver::Network)
    ->newPrintTask()
    ->content('Hello Network Printer!')
    ->send();

// Print via USB
$task = Printing::driver(PrintDriver::Usb)
    ->newPrintTask()
    ->content('Hello USB Printer!')
    ->send();

// Print a view as PDF
$task = Printing::newPrintTask()
    ->view('printing.invoice', ['data' => $invoiceData])
    ->pdf(['format' => 'A4'])
    ->send();
```

Supported Drivers
-----------------

[](#supported-drivers)

### 1. PrintNode (Cloud)

[](#1-printnode-cloud)

```
$task = Printing::driver(PrintDriver::PrintNode)->newPrintTask();
```

### 2. CUPS (Local Server)

[](#2-cups-local-server)

```
$task = Printing::driver(PrintDriver::Cups)->newPrintTask();
```

### 3. Network (TCP/IP)

[](#3-network-tcpip)

```
$task = Printing::driver(PrintDriver::Network)->newPrintTask();
```

### 4. USB (Direct Device)

[](#4-usb-direct-device)

```
$task = Printing::driver(PrintDriver::Usb)->newPrintTask();
```

### 5. Raw (Multi-Connection)

[](#5-raw-multi-connection)

```
$task = Printing::driver(PrintDriver::Raw)->newPrintTask();
```

Advanced Features
-----------------

[](#advanced-features)

### PDF Generation

[](#pdf-generation)

```
// HTML to PDF
$task = Printing::newPrintTask()
    ->content('InvoiceAmount: $100')
    ->pdf(['format' => 'A4', 'orientation' => 'portrait'])
    ->send();

// Save PDF
$pdfPath = Printing::newPrintTask()
    ->content('Document')
    ->pdf(['format' => 'A4'])
    ->save('document.pdf');
```

### View Printing

[](#view-printing)

Create a Blade view `resources/views/printing/receipt.blade.php`:

```

    Receipt

        body { font-family: monospace; }
        .center { text-align: center; }

        {{ $store_name }}
        Receipt #{{ $receipt_number }}

    @foreach($items as $item)
        {{ $item['name'] }} .................. ${{ $item['price'] }}
    @endforeach

    Total: ${{ $total }}

        Thank you for your purchase!

```

Print the view:

```
$receiptData = [
    'store_name' => 'My Store',
    'receipt_number' => '12345',
    'items' => [
        ['name' => 'Product 1', 'price' => '10.00'],
        ['name' => 'Product 2', 'price' => '15.00'],
    ],
    'total' => '25.00'
];

$task = Printing::newPrintTask()
    ->view('printing.receipt', $receiptData)
    ->pdf(['format' => 'A4'])
    ->send();
```

### Network Printing

[](#network-printing)

```
// Basic network printing
$task = Printing::driver(PrintDriver::Network)
    ->newPrintTask()
    ->content('Hello Network!')
    ->send();

// Specify different printer
$task = Printing::driver(PrintDriver::Network)
    ->newPrintTask()
    ->printer('192.168.1.101:9100')
    ->content('Different printer')
    ->send();

// Send raw data
$driver = Printing::driver(PrintDriver::Network);
$success = $driver->sendRawData('Raw commands', '192.168.1.100', 9100);

// Discover network printers
$printers = Printing::driver(PrintDriver::Network)
    ->printers(null, null, null, 'scan');
```

### USB Printing

[](#usb-printing)

```
// Basic USB printing
$task = Printing::driver(PrintDriver::Usb)
    ->newPrintTask()
    ->content('Hello USB!')
    ->send();

// ESC/POS commands for thermal printers
$escPos = "\x1B\x40"; // Initialize
$escPos .= "\x1B\x61\x01"; // Center align
$escPos .= "STORE RECEIPT\n";
$escPos .= "\x1B\x61\x00"; // Left align
$escPos .= "Item 1................$10.00\n";
$escPos .= "Total................$10.00\n";
$escPos .= "\x1D\x56\x41\x10"; // Cut paper

$task = Printing::driver(PrintDriver::Usb)
    ->newPrintTask()
    ->content($escPos)
    ->send();

// Discover USB printers
$printers = Printing::driver(PrintDriver::Usb)->printers();
```

### Raw Printing

[](#raw-printing)

Configure different connection types:

```
# Network raw printing
PRINTING_RAW_CONNECTION_TYPE=network
PRINTING_RAW_NETWORK_IP=192.168.1.100
PRINTING_RAW_NETWORK_PORT=9100

# USB raw printing
PRINTING_RAW_CONNECTION_TYPE=usb
PRINTING_RAW_USB_DEVICE_PATH=/dev/usb/lp0

# Parallel port printing
PRINTING_RAW_CONNECTION_TYPE=parallel
PRINTING_RAW_PARALLEL_PORT=LPT1

# Serial port printing
PRINTING_RAW_CONNECTION_TYPE=serial
PRINTING_RAW_SERIAL_PORT=COM1
PRINTING_RAW_SERIAL_BAUD_RATE=9600
```

```
$task = Printing::driver(PrintDriver::Raw)
    ->newPrintTask()
    ->content('Raw printing works with any connection type!')
    ->send();
```

### Excel/CSV Operations

[](#excelcsv-operations)

```
// Export to Excel
$excel = Printing::newPrintTask()
    ->export()
    ->excel($data, 'users.xlsx');

// Export to CSV
$csv = Printing::newPrintTask()
    ->export()
    ->csv($data, 'users.csv');

// Import from Excel
$data = Printing::newPrintTask()
    ->import()
    ->excel('users.xlsx');

// Import from CSV
$data = Printing::newPrintTask()
    ->import()
    ->csv('users.csv');
```

### Download Management

[](#download-management)

```
// Create downloadable file
$download = Printing::newPrintTask()
    ->content('File content')
    ->download('filename.txt');

// Force download
return $download->forceDownload();

// Stream download
return $download->stream();
```

Configuration Reference
-----------------------

[](#configuration-reference)

The complete configuration file `config/printing.php`:

```
return [
    'driver' => env('PRINTING_DRIVER', 'printnode'),

    'drivers' => [
        'printnode' => [
            'key' => env('PRINTING_PRINTNODE_KEY'),
        ],

        'cups' => [
            'ip' => env('PRINTING_CUPS_IP', '127.0.0.1'),
            'port' => env('PRINTING_CUPS_PORT', 631),
            'username' => env('PRINTING_CUPS_USERNAME'),
            'password' => env('PRINTING_CUPS_PASSWORD'),
        ],

        'network' => [
            'ip' => env('PRINTING_NETWORK_IP'),
            'port' => env('PRINTING_NETWORK_PORT', 9100),
            'timeout' => env('PRINTING_NETWORK_TIMEOUT', 30),
        ],

        'usb' => [
            'device_path' => env('PRINTING_USB_DEVICE_PATH'),
            'vendor_id' => env('PRINTING_USB_VENDOR_ID'),
            'product_id' => env('PRINTING_USB_PRODUCT_ID'),
            'timeout' => env('PRINTING_USB_TIMEOUT', 30),
        ],

        'raw' => [
            'connection_type' => env('PRINTING_RAW_CONNECTION_TYPE', 'network'),
            'network' => [
                'ip' => env('PRINTING_RAW_NETWORK_IP'),
                'port' => env('PRINTING_RAW_NETWORK_PORT', 9100),
                'timeout' => env('PRINTING_RAW_NETWORK_TIMEOUT', 30),
            ],
            'usb' => [
                'device_path' => env('PRINTING_RAW_USB_DEVICE_PATH'),
            ],
            'parallel' => [
                'port' => env('PRINTING_RAW_PARALLEL_PORT', 'LPT1'),
            ],
            'serial' => [
                'port' => env('PRINTING_RAW_SERIAL_PORT', 'COM1'),
                'baud_rate' => env('PRINTING_RAW_SERIAL_BAUD_RATE', 9600),
                'data_bits' => env('PRINTING_RAW_SERIAL_DATA_BITS', 8),
                'stop_bits' => env('PRINTING_RAW_SERIAL_STOP_BITS', 1),
                'parity' => env('PRINTING_RAW_SERIAL_PARITY', 'none'),
            ],
        ],
    ],
];
```

Error Handling
--------------

[](#error-handling)

```
use Xslain\Printing\Exceptions\PrintingException;

try {
    $task = Printing::driver(PrintDriver::Network)
        ->newPrintTask()
        ->content('Test print')
        ->send();

    echo "Print successful!";
} catch (PrintingException $e) {
    echo "Print failed: " . $e->getMessage();
}
```

Platform Support
----------------

[](#platform-support)

PlatformNetworkUSBParallelSerialLinux✅✅✅✅Windows✅⚠️✅✅macOS✅⚠️⚠️⚠️- ✅ Full support
- ⚠️ Limited support
- ❌ Not supported

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 10.0+
- For PDF: DomPDF or mPDF
- For Excel: PhpSpreadsheet
- For USB on Linux: `lsusb` command
- Network access for network printing

Testing
-------

[](#testing)

```
composer test
```

Examples
--------

[](#examples)

Check the `examples/` directory for comprehensive usage examples:

- `examples/network-usb-printing.php` - Network and USB printing examples
- More examples coming soon...

Custom Drivers
--------------

[](#custom-drivers)

Extend with custom drivers:

```
use Xslain\Printing\Facades\Printing;

Printing::extend('custom', function ($config) {
    return new CustomDriver($config);
});

$task = Printing::driver('custom')
    ->newPrintTask()
    ->content('Custom driver')
    ->send();
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Randall Wilk](https://github.com/xslain) - Original package author
- [All Contributors](../../contributors)
- *Mike42* for the [PHP ESC/POS Print Driver](https://github.com/mike42/escpos-php) library

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

---

Additional Resources
--------------------

[](#additional-resources)

- [Laravel Documentation](https://laravel.com/docs)
- [PrintNode API](https://printnode.com/docs/api)
- [CUPS Documentation](https://www.cups.org/documentation.html)
- [ESC/POS Command Reference](https://reference.epson-biz.com/modules/ref_escpos/)

For more detailed documentation and advanced usage examples, visit:

- [PrintNode/PrintNode-PHP](https://github.com/PrintNode/PrintNode-PHP)
- [phatkoala/printnode](https://github.com/PhatKoala/PrintNode)

Inspiration for certain aspects of the API implementations comes from:

- [stripe-php](https://github.com/stripe/stripe-php)

Disclaimer
----------

[](#disclaimer)

This package is not affiliated with, maintained, authorized, endorsed or sponsored by Laravel or any of its affiliates.

License
-------

[](#license-1)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance57

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

284d ago

Major Versions

1.0.0 → 2.0.02025-09-23

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/146024660?v=4)[xslain](/maintainers/xslain)[@Xslain](https://github.com/Xslain)

---

Top Contributors

[![ogoungaemmanuel](https://avatars.githubusercontent.com/u/20252938?v=4)](https://github.com/ogoungaemmanuel "ogoungaemmanuel (2 commits)")

---

Tags

PrintNodeCUPSlaravel-printingReceipt printingDirect printingRaw printingippxslain

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/xslain-laravel-printing/health.svg)

```
[![Health](https://phpackages.com/badges/xslain-laravel-printing/health.svg)](https://phpackages.com/packages/xslain-laravel-printing)
```

###  Alternatives

[rawilk/laravel-printing

Direct printing for Laravel apps

566288.0k9](/packages/rawilk-laravel-printing)[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[nativephp/mobile

NativePHP for Mobile

1.1k75.1k91](/packages/nativephp-mobile)[spatie/laravel-health

Monitor the health of a Laravel application

87512.0M165](/packages/spatie-laravel-health)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5021.9k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
