Date : 2023-12-09
Type : 操作系统
Model : LINUX
Title : Table-formatted text #123 ESCPOS-PHP
From : https://github.com/mike42/escpos-php/issues/123
Table-formatted text #123
Closed
skyvory opened this issue May 12, 2016 · 12 comments
Closed
Table-formatted text
#123
skyvory opened this issue May 12, 2016 · 12 comments
Comments
@skyvory
skyvory commented May 12, 2016
Is it possible to format the text as if it's printed on a table?
I'd like to print multiple column of text where each of them is right aligned.
For example, a line consist of "item name", "quantity", "price per item", and "total price" would all be printed right aligned in their own column except for "item name" which is left aligned.
FYI, I use Epson LX-310 on Windows.
@skyvory
Author
skyvory commented May 12, 2016
Never mind. I achieved the desired result by using sprintf() to arrange the spacing/padding of the text.
@skyvory skyvory closed this as completed May 12, 2016
@haithem-rihane
haithem-rihane commented May 12, 2016
Can u share us ur code how u used sprintf() to arrange the spacing/padding of the text.
Thanks
@skyvory
Author
skyvory commented May 13, 2016
Sure do.
$connector = new FilePrintConnector("php://stdout");
$printer = new Printer($connector);
// loop
$line = sprintf('%-40.40s %5.0f %13.2f %13.2f', $item_name, $quantity, $price, $total);
$printer->text($line);
$printer->text("\n");
// end loop
$printer -> close();
Sorry that I couldn't explain it in detail because I haven't fully grasped how sprintf() works.
Basically 40 characters for item name, 5 for quantity, and 13 with 2 decimal digits for price and total.
It was trial and error until I found the perfect fit of the spacing.
@haithem-rihane
haithem-rihane commented May 13, 2016
Nice , and thanks for sharing ;)
@Leonardus-dot
Leonardus-dot commented Apr 10, 2019 •
I was trial and error , and i use and I use thermal paper with a size of 80 * 80 , and i try format number with my functions:
looping the data from databases:
$line = sprintf('%-13.40s %3.0f %-3.40s %9.40s %-2.40s %13.40s',$row['item_code'] , $row['item_qty'], $row['kali'], $n1,$row['hasil'], $n2);
$printer -> text("$line\n");
And transactions info :
$lineTotal = sprintf('%-5.40s %-1.05s %13.40s','Total Belanja.','=', $tot1);
$printer -> text("$lineTotal\n");
$lineTunai = sprintf('%-5.40s %-1.05s %13.40s','Uang Tunai.','=', $tot2);
$printer -> text("$lineTunai\n");
$lineDisc = sprintf('%-5.40s %-1.05s %13.40s','Disc.','=', $tot3);
$printer -> text("$lineDisc\n");
$lineKembalian = sprintf('%-5.40s %-1.05s %13.40s','Kembalian.','=', $tot4);
$printer -> text("$lineKembalian\n");
Result print images :
IMG_20190409_193520
@mountainclimbing
mountainclimbing commented Apr 16, 2019
@Leonardus-dot Please attach full code. Preferably even Sample .SQL database and full php code.
@mountainclimbing
mountainclimbing commented Apr 23, 2019
@Leonardus-dot Thanks!
@ahsanAsif26
ahsanAsif26 commented Jul 27, 2019
can i have the code please ??? just for design purpose.
Not the sql data.
Thanks
@ahsanAsif26
ahsanAsif26 commented Jul 27, 2019
@Leonardus-dot @mountainclimbing can i have the code please ??? just for design purpose.
Not the sql data.
Thanks
@Leonardus-dot
Leonardus-dot commented Aug 7, 2019
@Leonardus-dot @mountainclimbing can i have the code please ??? just for design purpose.
Not the sql data.
Thanks
ya, you can get the code , just pm me on gmail , leonardus25@gmail.com
@duvan177
duvan177 commented Aug 17, 2019
gracias amigo, esto es lo que necesitaba! toma tu like!
@nchankov nchankov mentioned this issue Jul 14, 2020
Star TSP100iii futurePrint - can't print any #944
Closed
@rimbawansr
rimbawansr commented Aug 4, 2020
@Leonardus-dot Please attach full code. Preferably even Sample .SQL database and full php code.
to join this conversation on GitHub. Already have an account? Sign in to comment
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development
No branches or pull requests
7 participants