ESC/POS printing barcode aligned vertically and horizontally in the middle?

青春壹個敷衍的年華 提交于 2021-01-29 12:30:36

问题


My code is currently printing a barcode and hri text easily, but I want everything to be printed dead centre on the label. Can someone please tell me when I should declare the alignment command?
I tried declaring it at the beginning and just before the barcode print command, but the barcode is still printing in the top left corner.
Here is my align command:

    def align_esc(self,esc,n):
        '''
        ESC|a|n
        0<=n<=2,48<=n<=50
        0,48 = Left; 1,49 = Mid; 2,50 = Right
        '''
        align = [esc,n]
        align_prnt = bytearray(align)
        return align

The reason I am not using escpos python library is because I am printing from an Android device.
Edit:
The above function is missing the following character on line 7:

align = [esc,97,n]

回答1:


In the ESC a command description of EPSON, there are the following notes.
Are these notices on the ESC a command for your printer?

  • When Standard mode is selected, this command is enabled only when processed at the beginning of the line in Standard mode.
  • The justification has no effect in Page mode.
  • This command executes justification in the print area set by GS L and GS W.
  • This command justifies printing data (such as characters, all graphics, barcodes, and two-dimensional code) and space area set by HT, ESC $, and ESC \.
  • Settings of this command are effective until ESC @ is executed, the printer is reset, or the power is turned off.

Often, the ESC a command is specified not after the beginning of the line but after printing a few characters or spaces.

For example, if you print with plain text instead of a barcode and it is not centered, then ESC a is not specified at the beginning of the line.
Change the ESC a command so that it is specified at the beginning of the line.

However, if the plain text is printed centered, the feature may not work for barcodes.
In that case, contact the printer vendor to determine if barcode alignment is available and how to do so.
Or there is no automatic function, it may be a method to adjust the print position with ESC \ etc.


The print position in the horizontal direction can be specified by either ESC $ or ESC \.
Only the starting point of the calculation is different. ESC $ is the left edge of the paper, and ESC \ is the print position at that time.
You won't need to use GS P.



来源:https://stackoverflow.com/questions/59480798/esc-pos-printing-barcode-aligned-vertically-and-horizontally-in-the-middle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!