How to print box drawing character using ESC/POS

1.3k Views Asked by At

I would like to print box drawing character using ESC/POS to Epson LQ310 dot matrix printer in android app. The sample printout would be as below,

enter image description here

Initially, I am using underscore and vertical bar to draw its borders. But the printout turned out to be with broken line. I would like to having continuous line instead.

Then I saw there is box drawing character with ASCII code as image attached,

Some characters for box drawing

Using those ASCII code info, I tried to print but the printout become other characters. I found out that it is due to different character set used in printer

Checking through the ESC/P command, there is only these 2 commands regarding character set.

ESC R
ESC t

Sample code I done as below, I just tried a few characters but it's to no avail. How to register the PC850 character set and use it using ESC t command?

char[] verticalLine = {0x00B3};
char[] verticalPlusLeft = {0x00B4};
char[] upperRightCorner = {0x00BF};
char[] bottomRightCorner = {0x00D9};
char[] upperLeftCorner = {0x00DA};
char[] bottomLeftCorner = {0x00C0};
char[] horizonLine = {0x00C4};
char[] verticalPlusRight = {0x00C3};
char[] charMultiLangual = {0x001B, 0x0074, 0x0002}; //ESC,t,2(PC850)
char[] charCodeDefault = {0x001B, 0x0074, 0x0000}; //ESC,t,0(Default)

strPrintFooterTitle = new String(charMultiLangual);
strPrintFooterTitle += printFooter(new String(upperLeftCorner), "TYPE", new String(verticalLine), "QTY", new String(upperRightCorner)) + "\n";
strPrintFooterBig = printFooter(new String(verticalLine), "Crate - Big", "|", "5", "|") + "\n";
strPrintFooterSmall = printFooter("|", "Crate - Small", "|", "10", "|") + "\n";
strPrintFooter = new String(charCodeDefault);

Any help is much appreciated. Thanks

1

There are 1 best solutions below

0
On

You can use exactly those box-drawing characters, not their codes, something like this:

System.out.println("┌───────────────────────┬───────┐");
System.out.println("│  Type                 │  QTY  │");
System.out.println("├───────────────────────┼───────┤");
System.out.println("│  Crate - Big          │    7  │");
System.out.println("├───────────────────────┼───────┤");
System.out.println("│  Crate - Small        │    3  │");
System.out.println("└───────────────────────┴───────┘");

Output:

┌───────────────────────┬───────┐
│  Type                 │  QTY  │
├───────────────────────┼───────┤
│  Crate - Big          │    7  │
├───────────────────────┼───────┤
│  Crate - Small        │    3  │
└───────────────────────┴───────┘

See also: How do I rotate a matrix 90 degrees counterclockwise in java?