Hello Since few days I am trying to print image on invoice on Android I did everything , logo got printed on invoice after searching few days but now I am getting issue that image not print on center I have followed all these steps to print image (http://new-grumpy-mentat.blogspot.com//2014/06/java-escpos-image-printing.html)
but this is what I am getting image on left side but i want this image on Center please guide me

- 83
- 10
2 Answers
There are two possible methods.
One is to prepare image data of the same size as the paper width and place the logo image in the center.
It is necessary to make large white parts on the left and right of the logo image that is currently visible, and prepare and send data even if that part is not printed, but customer requests have changed and the entire paper width will be used. However, the amount of data does not change.
By applying it, it is possible to reduce the data in the blank area on the right side by preparing only the data for the blank area on the left side of the image.
The other is to specify the centering of the print content with the ESC a command before printing the image.
This should be sent with no print request at the beginning of the line.
Please refer to this page.
ESC a
[Name]
Select justification[Format]
ASCII ESC a n Hex 1B 61 n Decimal 27 97 n n Justification 0, 48 Left justification 1, 49 Centered 2, 50 Right justification
After printing the logo, it is necessary to return the centering to the left.

- 4,060
- 2
- 10
- 30
-
can i have some piece of code? or any way to find the printer paper width ? – Bakhtiyar Hussain Oct 23 '20 at 11:50
-
For example, both answers in this article will be helpful. [ESC/POS thermal printer, how to center a bitmap image in Android?](https://stackoverflow.com/q/49818789/9014308) The paper width will be written in the user's manual or specifications. – kunif Oct 23 '20 at 12:07
-
can't i get paper width programmaticaly? – Bakhtiyar Hussain Oct 26 '20 at 09:43
-
On the contrary, why should it be read programmatically? If you are making it as a library, you can specify it from the application, and if it is an application, it is unlikely that the paper width is not decided at the time of actual business. This is because you need to purchase and prepare a printer and roll paper. – kunif Oct 26 '20 at 09:51
-
because there are different type of users some use 48mm size of paper and some 80mm – Bakhtiyar Hussain Oct 26 '20 at 09:53
-
Isn't it better to make it possible to use a file that stores setting information such as an ini file or a configuration file so that a numerical value can be specified for it? If you really want to switch between multiple types at any given time, you can allow users to select candidates in a list. Either way, that should be asked separately as a new question. – kunif Oct 26 '20 at 10:01
Add this printer command
public static final byte[] ESC_ALIGN_CENTER = new byte[] { 0x1b, 'a', 0x01 };

- 29,388
- 11
- 94
- 103

- 247
- 2
- 9