PHP code example of abdullah-life / laravel-zebra-image-printer

1. Go to this page and download the library: Download abdullah-life/laravel-zebra-image-printer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

abdullah-life / laravel-zebra-image-printer example snippets


use AbdullahLife\ZebraImagePrinter\Facades\ZebraPrinter;

// Print local file with 1cm margin
ZebraPrinter::print('/path/to/label.png', 1);

// Print remote URL
ZebraPrinter::print('https://example.com/label.png', 1);

// Print with custom margin
ZebraPrinter::print('/path/to/label.png', 0.5);

// Check if printer is online
if (ZebraPrinter::isOnline()) {
    ZebraPrinter::print('/path/to/label.png');
}

use AbdullahLife\ZebraImagePrinter\ZebraPrinter;

class LabelController extends Controller
{
    public function print(ZebraPrinter $printer)
    {
        $printer->print(storage_path('labels/shipping-label.png'), 1);

        return response()->json(['status' => 'printed']);
    }
}

use AbdullahLife\ZebraImagePrinter\Facades\ZebraPrinter;

// Convert to ZPL without printing
$zpl = ZebraPrinter::convert('/path/to/label.png', 1);

// Send ZPL to different printer
ZebraPrinter::sendToPrinter($zpl, '192.168.1.100', 9100);

// Check specific printer
$isOnline = ZebraPrinter::isOnline('192.168.1.100', 9100);

return [
    'printer_ip' => env('ZEBRA_PRINTER_IP', '172.21.54.45'),
    'printer_port' => env('ZEBRA_PRINTER_PORT', 9100),
    'dpi' => env('ZEBRA_PRINTER_DPI', 203),
    'direct_thermal' => env('ZEBRA_PRINTER_DIRECT_THERMAL', true),
    'darkness' => env('ZEBRA_PRINTER_DARKNESS', 30),
    'page_width_dots' => env('ZEBRA_PRINTER_PAGE_WIDTH', 832),
];

// Check connection
if (!ZebraPrinter::isOnline()) {
    throw new Exception('Printer offline');
}