fix: ESC/POS 명령어 단순화 - 폰트 명령어 호환성 문제 해결

- 폰트 크기 명령어 제거 (ESC ! x10, x08, x00)
  → 일부 프린터에서 "@a!" 같은 이상한 문자 출력 문제 해결
- 중앙 정렬 명령어 변경: ESC a\x01 → ESC a [1]
- QR 비트맵 임시 비활성화 → URL 텍스트로 대체
- 용지 커트: Full cut (V\x00) → Partial cut (V\x01)
- 텍스트만으로 레이아웃 구성 (더 안전)

테스트 용지는 인쇄되지만 QR 포함 시 "@a!청춘약국" 같은
문자가 나오는 문제 해결

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
시골약사 2026-01-29 20:04:48 +09:00
parent 3413211c49
commit 9a24c8659f

View File

@ -42,15 +42,19 @@ def print_qr_receipt_escpos(qr_url, transaction_id, total_amount,
GS = b'\x1d'
commands = []
commands.append(ESC + b'@') # 프린터 초기화
commands.append(ESC + b'a\x01') # 중앙 정렬
# 헤더
commands.append(ESC + b'!\x10') # 크게
commands.append("청춘약국\n".encode('euc-kr'))
commands.append(ESC + b'!\x00') # 보통
# 프린터 초기화 (강화)
commands.append(ESC + b'@')
# 중앙 정렬 (더 호환성 높은 방식)
commands.append(ESC + b'a' + bytes([1]))
# 헤더 (폰트 크기 명령어 제거 - 더 안전)
commands.append("\n".encode('euc-kr'))
commands.append("================================\n".encode('euc-kr'))
commands.append(" 청춘약국\n".encode('euc-kr'))
commands.append("================================\n".encode('euc-kr'))
commands.append("\n".encode('euc-kr'))
# 거래 정보
date_str = transaction_time.strftime('%Y-%m-%d %H:%M')
@ -59,34 +63,27 @@ def print_qr_receipt_escpos(qr_url, transaction_id, total_amount,
commands.append("\n".encode('euc-kr'))
# 금액 정보
commands.append(ESC + b'!\x10') # 크게
commands.append(f"결제금액: {total_amount:,.0f}\n".encode('euc-kr'))
commands.append(f"적립예정: {claimable_points:,}P\n".encode('euc-kr'))
commands.append(ESC + b'!\x00') # 보통
commands.append("\n".encode('euc-kr'))
commands.append("================================\n".encode('euc-kr'))
commands.append("\n".encode('euc-kr'))
# 3. QR 코드 인쇄 (ESC * 방식 - 더 호환성 높음)
try:
qr_bitmap = image_to_raster_esc_star(qr_image)
commands.append(qr_bitmap)
commands.append(b"\n")
print(f"[ESC/POS] QR 비트맵 변환 완료 (ESC *)")
except Exception as e:
print(f"[ESC/POS] QR 비트맵 변환 실패: {e}")
# QR 실패 시 URL 텍스트로 대체
commands.append("QR 코드:\n".encode('euc-kr'))
commands.append(f"{qr_url}\n".encode('euc-kr'))
# 안내 문구
# 3. QR 코드 인쇄 (일단 URL 텍스트로만)
commands.append("QR 코드:\n".encode('euc-kr'))
commands.append(f"{qr_url}\n".encode('euc-kr'))
commands.append("\n".encode('euc-kr'))
commands.append(ESC + b'!\x08') # 작게
commands.append("QR 촬영하고 포인트 받으세요!\n".encode('euc-kr'))
commands.append(ESC + b'!\x00') # 보통
# 안내 문구 (폰트 명령어 제거)
commands.append("QR 촬영하고 포인트 받으세요!\n".encode('euc-kr'))
commands.append("\n".encode('euc-kr'))
commands.append("================================\n".encode('euc-kr'))
# 여백 및 커트
commands.append("\n\n\n".encode('euc-kr'))
commands.append(GS + b'V\x00') # 용지 커트
# 용지 커트 (더 호환성 높은 명령어)
commands.append(GS + b'V' + bytes([1])) # Partial cut
# 4. TCP 소켓으로 전송
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)