Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

str_pad will result in a new line #544

Closed
dpayet opened this issue Mar 15, 2018 · 5 comments
Closed

str_pad will result in a new line #544

dpayet opened this issue Mar 15, 2018 · 5 comments
Labels

Comments

@dpayet
Copy link

dpayet commented Mar 15, 2018

Hello,

I've tried the receipt-with-logo example and the lines are not aligned on right. It does a new line below the first. I have the item on the left and its price below the item (it should be on the right).

My printer is a Epson TM-T88IV. Is there any config to do to adjust the paper width or the print size (or something else ?) :)
Thanks (and sorry for my english).
29261500_10208750308873721_2964178959303966720_o

@mike42
Copy link
Owner

mike42 commented Mar 15, 2018

You might just need to change some numbers. I wrote that example for a printer with 48 characters per line and your printer looks like it's narrower, maybe 42.

Look for $leftCols and $rightCols in the example.

class item
{
...
    public function __toString()
    {
        $rightCols = 10;
        $leftCols = 38;

        if ($this -> dollarSign) {
            $leftCols = $leftCols / 2 - $rightCols / 2;
        }
        $left = str_pad($this -> name, $leftCols) ;
        
        $sign = ($this -> dollarSign ? '$ ' : '');
        $right = str_pad($sign . $this -> price, $rightCols, ' ', STR_PAD_LEFT);
        return "$left$right\n";
    }
}

It is currently 38 + 10 (48 columns total), you need to make these numbers smaller, maybe start with 34 + 8 and decrease from there if the lines still wrap,

@dpayet
Copy link
Author

dpayet commented Mar 16, 2018

Shame on me, I should have seen this ...

Big thanks mike ! :)

@mike42
Copy link
Owner

mike42 commented Mar 17, 2018

I also notice that you have an "ñ" sign on your receipt. Since you are writing in French, I'm guessing you are trying to print a Euro.

If you upgrade to v2.0.1, you can use the CapabilityProfile called TM-T88IV which should correct this for your specific printer.

A sort of minimal example would be-

use Mike42\Escpos\CapabilityProfile;
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;

$profile = CapabilityProfile::load("TM-T88IV");
$connector = new FilePrintConnector("/dev/usb/lp0");
$printer = new Printer($connector, $profile);

$printer -> text("Article gratuit      € 0,00\n");

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

@mike42 mike42 closed this as completed Mar 23, 2018
@dpayet
Copy link
Author

dpayet commented Mar 25, 2018

Thanks you so much !

@umardevid
Copy link

can i use grid

  1. for qty
  2. for product name (add line break if text to long)
  3. for price

20 Indomie Goreng(break if long text) Rp12.500 IDR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants