0

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

7
  • Your printer insn't here driver may no work. Commented Mar 5 at 11:17
  • @francisco Thanks for highlighting that! Any suggestions for the next steps? Commented Mar 5 at 12:02
  • Use another lib, or make sure that you have the proper hardware to test this lib. Commented Mar 5 at 12:18
  • @francisco I tried to print using the command prompt but no output PS C:\Users**********> print /D:"\\DESKTOP-******\XP-246B" test.txt C:\Users**********\test.txt is currently being printed Commented Mar 5 at 17:53
  • you know the code passes there but don't do anything on your printer... Commented Mar 6 at 9:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.