mike42 / escpos-php

PHP library for printing to ESC/POS-compatible thermal and impact printers
Other
2.58k stars 863 forks source link

basic Samsung laser printer #1294

Open CHILLTH opened 1 year ago

CHILLTH commented 1 year ago

Hi guys! Trying to test printing pdf via IP as per below code, however it doesnt printing out PDF content but some random chars and mostly blank pages. What should be done?

`<?php require 'vendor/autoload.php'; // Include the escpos-php library

use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;

use Mike42\Escpos\Printer; use Mike42\Escpos\ImagickEscposImage;

// IP address and port of the printer server $printerIP = 'MYIP'; $printerPort = 9100;

try { // Create a network connector to the printer $connector = new NetworkPrintConnector($printerIP, $printerPort);

// Create a new Printer object
$printer = new Printer($connector);

// Path to the PDF file you want to print
$pdfFilePath = 'sample.pdf';

$pages = ImagickEscposImage::loadPdf($pdfFilePath, 260);
foreach ($pages as $page) {
    $printer -> graphics($page, Printer::IMG_DOUBLE_HEIGHT | Printer::IMG_DOUBLE_WIDTH);
}

$printer->cut();
$printer -> close();

echo 'PDF printed successfully!';

} catch (Exception $e) { echo 'Error: ' . $e->getMessage(); } ?>

`

CHILLTH commented 1 year ago

Happy to hire for that too :)