escpos-php icon indicating copy to clipboard operation
escpos-php copied to clipboard

does not print the image in win10

Open cardenas56 opened this issue 3 years ago • 0 comments

Hi guys, I'm using the library to print tickets with images. I have already implemented the library in Linux (Ubuntu) and it works correctly but in Windows 10 it does not print the image. I use the same code in both operating systems. I am using PHP 8.

<?php
require '../../../resources/commons/lib/vendor/autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\EscposImage;
//use Mike42\Escpos\GdEscposImage;
use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;

    $connector = new NetworkPrintConnector($this->ip_printers, $this->port);
    $printer = new Printer($connector);
    
    $hh = new Item("4.00", "Unid.", "Totales");
    $items = array(
        array("Example item #1",new Item("4.00", strval(random_int(1, 20)), "4.00")),
        array("Another thing", new Item("3.50", strval(random_int(1, 20)), "3.50")),
        array("Something else", new Item("1.00", strval(random_int(1, 20)), "1.00")),
        array("A final item", new Item("4.45", strval(random_int(1, 20)), "4.45")),
    ); 
    // $subtotal = new Item('Subtotal', '12.95');
    // $tax = new Item('A local tax', '1.30');
    // $total = new Item('Total', '14.25', true); 

    // //Date is kept the same for testing 
    // $date = date('l jS \of F Y h:i:s A');
    // $date = "Monday 6th of April 2015 02:56:25 PM"; 
    
    // /* Start the printer */
    $logo = EscposImage::load("tux.bmp",false);
    // $logo = new GdEscposImage("tux.jpg");
    
    $printer -> setJustification(Printer::JUSTIFY_CENTER);
    $printer -> bitImage($logo);//, Printer::IMG_DOUBLE_WIDTH);

    $printer -> setJustification(Printer::JUSTIFY_CENTER);
    $printer -> text("Fecha 23/06/2022 15:19:59 \n");
    
    $printer -> text("Agencia DROI SAS\n");
    $printer -> selectPrintMode();
    $printer -> text("Nit: 1234567890-1\n");
    $printer -> selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
    $printer -> text("--FACTURA DE VENTA--\n");

    $printer -> selectPrintMode(Printer::MODE_FONT_A);
    $printer -> setEmphasis(true);
    $printer -> text("\nDROI Villavicencio\n");
    $printer -> setEmphasis(false);
    $printer -> setJustification(Printer::JUSTIFY_RIGHT);            
    $printer -> text("# FACT 152269\n");

    $printer -> setJustification(Printer::JUSTIFY_LEFT);
    $printer -> text("CAJERO: Camilo Cardenas\n");
    $printer -> text("\n");
    
    $printer -> setEmphasis(true);
    $printer -> text("Razón social");
    $printer -> setEmphasis(false);
    $printer -> text(" Pepito Perez\n");
    $printer -> setEmphasis(true);
    $printer -> text("Nit:");
    $printer -> setEmphasis(false);
    $printer -> text("          111111111111\n");
    
    $printer -> text("________________________________________________\n");
    
    $printer -> text("Producto\n");
    $printer -> text($hh)."\n";
    $printer -> text("________________________________________________\n");
    foreach ($items as $item) {
        $printer -> text($item[0]."\n");
        $printer -> text($item[1])."\n";
    }
    $printer -> text("________________________________________________\n");
    $printer -> text("Condiciones de pago: Contado\n");
    $printer -> text("Metodo de pago: Efectivo\n");
    $printer -> setJustification(Printer::JUSTIFY_RIGHT); 
    $printer -> text("$ 20.000\n");
    $printer -> text("________________________________________________\n");
    $printer -> setJustification(Printer::JUSTIFY_CENTER);
    $printer -> text("---------Contacto---------\n");

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

    class Item
    {
        private $name;
        private $unit;
        private $price;
        private $dollarSign;
    
        public function __construct($name = '', $unit, $price = '', $dollarSign = true)
        {
            $this -> name = $name;
            $this -> unit = $unit;
            $this -> price = $price;
            $this -> dollarSign = $dollarSign;
        }
    
        public function __toString()
        {
            $rightCols = 10;
            $centerCols = 10;
            $leftCols = 28;
            // if ($this -> dollarSign) {
            //     $leftCols = $leftCols / 2 - $rightCols / 2;
            // }
            $left = str_pad($this -> name, $leftCols) ;
            $center = str_pad($this->unit, $centerCols) ;
            $sign = ($this -> dollarSign ? '$ ' : '');
            $right = str_pad($sign . $this -> price, $rightCols, ' ', STR_PAD_RIGHT);
            return "$left$center$right\n";
        }
    }

Test image tux.zip

cardenas56 avatar Jul 12 '22 21:07 cardenas56