I'm using an XP-246B thermal printer. I have shared the printer and ensured that its name doesn't contain any whitespace. Also, I ran a test through Windows built in test page, and it was successful.
The lib I'm currently using to connect: Mike42\Escpos
My Printing logic
public function printLabelService($title, $isbn, $price, $location)
{
try {
Log::info('Attempting to initialize printer with connector.');
$connector = new WindowsPrintConnector("XP-246B");
Log::info('Printer connector created.');
$printer = new Printer($connector);
Log::info('Printer object created.');
if ($printer) {
Log::info('Printer initialized successfully.');
$printer->setJustification(Printer::JUSTIFY_CENTER);
$printer->text("Titre: " . $title . "\n");
Log::info('Printed title: ' . $title);
$printer->text("ISBN: " . $isbn . "\n");
Log::info('Printed ISBN: ' . $isbn);
$printer->text("Prix: " . $price . "\n");
Log::info('Printed price: ' . $price);
$printer->text("Location: " . $location . "\n");
Log::info('Printed location: ' . $location);
Log::info('Starting to print.');
$printer->cut();
Log::info('Printed label for book: ' . $title);
$printer->close();
Log::info('Printer closed successfully.');
}
} catch (Exception $e) {
Log::error('Failed to print label: ' . $e->getMessage());
throw new Exception("Failed to print label: " . $e->getMessage());
}
}
My server logs
[2025-03-04 12:38:36] local.INFO: Attempting to initialize printer with connector.
[2025-03-04 12:38:36] local.INFO: Printer connector created.
[2025-03-04 12:38:36] local.INFO: Printer object created.
[2025-03-04 12:38:36] local.INFO: Printer initialized successfully.
[2025-03-04 12:38:36] local.INFO: Printed title: Eos voluptate rerum.
[2025-03-04 12:38:36] local.INFO: Printed ISBN: 9781591213314
[2025-03-04 12:38:36] local.INFO: Printed price: 93.43
[2025-03-04 12:38:36] local.INFO: Printed location: tempora
[2025-03-04 12:38:36] local.INFO: Starting to print.
[2025-03-04 12:38:36] local.INFO: Printed label for book: Eos voluptate rerum.
[2025-03-04 12:38:36] local.INFO: Printer closed successfully.
Unfortunately, nothing happens. nor an error nor a successful printing
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745041272a4607822.html
评论列表(0条)