mike42 / escpos-php

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

Inconsistant receipt printing output #1342

Open Rana-xD opened 2 months ago

Rana-xD commented 2 months ago

I have an issue when sometime it print correctly and something it is not (on top part). And I don't know what is the issue. Below is my custom code

public function printXscometicReceipt(){
        if ($this->printer) {
            // Get request amount
            $total = $this->getPrintableSummary('TOTAL', $this->request_amount, true);
            $seller = $this->getPrintableHeader(
                'Seller: ',
                $this->cashier
            );
            $date = $this->getPrintableHeader(
                'Date: ',
                date('d-m-Y / h:i A'),
            );

            $total_discount = $this->getPrintableHeader(
                'Discount All    :',
                $this->discount_all,
            );

            $total = $this->getPrintableHeader(
                'Total      ($)  :',
                $this->total
            );

            $total_riel = $this->getPrintableHeader(
                'Total      (KHR):',
                $this->total_riel,
            );

            $recieve_in_usd = $this->getPrintableHeader(
                'Recieve    ($)  : ',
                '$'.$this->received_in_usd,
            );

            $received_in_riel =  $this->getPrintableHeader(
                'Recieve    (KHR): ',
                $this->received_in_riel,
            );

            $change_in_usd =  $this->getPrintableHeader(
                'Change    ($)  : ',
                '$'.$this->change_in_usd,
            );

            $change_in_riel =  $this->getPrintableHeader(
                'Change    (KHR):',
                str_replace(' ៛','',$this->change_in_riel),
            );

            $product_header = ['Name', 'Price', 'Qty', 'Total'];
            // Init printer settings
            $this->printer->initialize();

            $this->printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
            $this->printer->setJustification(Printer::JUSTIFY_CENTER);

            $this->printer->text("{$this->store->getName()}\n");
            $this->printer->selectPrintMode(Printer::MODE_FONT_A);
            $this->printer->setJustification(Printer::JUSTIFY_CENTER);
            $this->printer->text($seller . "\n");
            $this->printer->text($date . "\n");

            $this->printDashedLine();
            $this->printer->setEmphasis(true);

            $this->printer->selectPrintMode(Printer::MODE_FONT_A);
            $this->printer->setJustification(Printer::JUSTIFY_LEFT);

            $this->printer->text($this->getReceiptHeader());

            $this->printer->setEmphasis(false);
            $this->printer->feed();
            foreach ($this->items as $item) {

                $this->printer->text($item."\n");
            }
            $this->printer->setJustification(Printer::JUSTIFY_CENTER);
            $this->printDashedLine();
            $this->printer->selectPrintMode(Printer::MODE_FONT_A);
            $this->printer->text($total_discount . "\n");
            $this->printer->text($total . "\n");
            $this->printer->text($total_riel . "\n");
            $this->printer->text($recieve_in_usd . "\n");
            $this->printer->text($received_in_riel . "\n");
            $this->printDashedLine();
            $this->printer->text($change_in_usd . "\n");
            $this->printer->text($change_in_riel . "\n");
            $this->printDashedLine();

            $this->printNote();

            $this->printer->cut();
            $this->printer->close();
        } else {
            throw new Exception('Printer has not been initialized.');
        }
    }

You can check the image attachment.

IMG_6826

My OS is Mac and My Thermal Printer Model is Rongta RP80USE.