PHP code example of 6amtech / laravel-electron-printing

1. Go to this page and download the library: Download 6amtech/laravel-electron-printing 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/ */

    

6amtech / laravel-electron-printing example snippets


use LaravelElectronPrinting\Facades\ElectronPrint;

ElectronPrint::printView('receipt', ['order' => $order], null, 'thermal_80mm');

use LaravelElectronPrinting\Facades\ElectronPrint;

// Print HTML
ElectronPrint::printHtml('<h1>Hello World</h1>');

// Print Blade view
ElectronPrint::printView('receipt', ['order' => $order]);

// Print to specific printer
ElectronPrint::printView('receipt', $data, 'EPSON TM-T88V');

// Thermal 80mm receipt
ElectronPrint::printView('receipt', $data, null, 'thermal_80mm');

// Thermal 58mm receipt
ElectronPrint::printView('receipt', $data, null, 'thermal_58mm');

// A4 document
ElectronPrint::printView('invoice', $data, null, 'a4');

// A4 landscape
ElectronPrint::printView('report', $data, null, 'a4_landscape');

// Label printer
ElectronPrint::printView('label', $data, null, 'label');

ElectronPrint::printView('receipt', $data, null, [
    'pageSize' => ['width' => 80000, 'height' => 297000],
    'marginsType' => 1,
    'printBackground' => true,
    'scaleFactor' => 100
]);

// From file
ElectronPrint::printPdfFile(storage_path('app/invoice.pdf'));

// From URL
ElectronPrint::printPdfUrl('https://example.com/invoice.pdf');

// From Base64
ElectronPrint::printPdfBase64($base64String);

// With profile
ElectronPrint::printPdfFile(storage_path('app/invoice.pdf'), null, 'a4');

ElectronPrint::printUrl('https://example.com/receipt');

$printers = ElectronPrint::getPrinters();
// Returns: ['EPSON TM-T88V', 'HP LaserJet', ...]

if (ElectronPrint::isHealthy()) {
    // Service is running
}

'profiles' => [
    'my_custom_printer' => [
        'pageSize' => ['width' => 80000, 'height' => 297000],
        'marginsType' => 1,
        'printBackground' => true,
        'scaleFactor' => 100,
    ],
],

ElectronPrint::printView('receipt', $data, null, 'my_custom_printer');

// Kitchen printer
ElectronPrint::printView('kitchen-order', $data, 'Kitchen Printer', 'thermal_80mm');

// Counter printer (different service)
$counterService = new ElectronPrintService('http://192.168.1.101:3001');
$counterService->printView('receipt', $data, 'Receipt Printer', 'thermal_80mm');

use LaravelElectronPrinting\Facades\ElectronPrint;

// Print methods
ElectronPrint::printHtml($html, $printer, $options)
ElectronPrint::printView($view, $data, $printer, $options)
ElectronPrint::printUrl($url, $printer, $options)
ElectronPrint::printPdfFile($path, $printer, $options)
ElectronPrint::printPdfUrl($url, $printer, $options)
ElectronPrint::printPdfBase64($base64, $printer, $options)

// Utility
ElectronPrint::getPrinters()  // Returns array of printer names
ElectronPrint::isHealthy()    // Returns true if service running

// All methods return: ['success' => bool, 'message' => string]

   dd(ElectronPrint::getPrinters());
   
bash
php artisan electron-printing:install