fix: 동물약 안내서 인쇄를 네트워크 프린터로 변경

- USB 프린터에서 네트워크 프린터(192.168.0.174:9100)로 변경
- pos_printer.print_text() 함수 사용 (특이사항 인쇄와 동일 방식)
- 80mm 프린터 기준 48자 레이아웃
This commit is contained in:
thug0bin
2026-03-04 19:20:26 +09:00
parent 321fd0de1e
commit 097bc4c84f

View File

@@ -6504,93 +6504,68 @@ def api_animal_drug_info_print():
dosage = strip_html(row.dosage_instructions) dosage = strip_html(row.dosage_instructions)
precautions = strip_html(row.precautions) precautions = strip_html(row.precautions)
# ESC/POS 인쇄 데이터 생성 # 80mm 프린터 = 48자 기준
from escpos.printer import Usb LINE = "=" * 48
THIN = "-" * 48
# 프린터 연결 (아침에 설정한 영수증 프린터) # 텍스트 메시지 생성
try: message = f"""
# POS 프린터 (VID/PID 확인 필요) {LINE}
printer = Usb(0x0483, 0x5743, profile="default") 🐾 동물약 안내서
except Exception as e: {LINE}
logging.error(f"프린터 연결 실패: {e}")
return jsonify({'success': False, 'error': f'프린터 연결 실패: {str(e)}'}), 500 {pg_product_name}
"""
if company:
message += f"제조: {company}\n"
try: if ingredient and ingredient != 'NaN':
# 헤더 message += f"""
printer.set(align='center', bold=True, double_height=True) {THIN}
printer.text("🐾 동물약 안내서\n") ▶ 주성분
printer.set(align='center', bold=False, double_height=False) """
printer.text("=" * 42 + "\n\n") for line in wrap_text(ingredient, 46):
message += f" {line}\n"
# 제품명
printer.set(align='center', bold=True) if efficacy:
printer.text(f"{pg_product_name}\n") message += f"""
printer.set(bold=False) {THIN}
if company: ▶ 효능효과
printer.text(f"제조: {company}\n") """
printer.text("\n") for line in wrap_text(efficacy[:400], 46):
message += f" {line}\n"
# 주성분
if ingredient and ingredient != 'NaN': if dosage:
printer.set(align='left') message += f"""
printer.text("-" * 42 + "\n") {THIN}
printer.set(bold=True) ▶ 용법용량
printer.text("▶ 주성분\n") """
printer.set(bold=False) for line in wrap_text(dosage[:500], 46):
for line in wrap_text(ingredient): message += f" {line}\n"
printer.text(f" {line}\n")
printer.text("\n") if precautions:
message += f"""
# 효능효과 {THIN}
if efficacy: ▶ 주의사항
printer.set(align='left') """
printer.text("-" * 42 + "\n") for line in wrap_text(precautions[:400], 46):
printer.set(bold=True) message += f" {line}\n"
printer.text("▶ 효능효과\n")
printer.set(bold=False) message += f"""
for line in wrap_text(efficacy[:300]): # 최대 300자 {LINE}
printer.text(f" {line}\n") 청 춘 약 국
printer.text("\n") Tel: 033-481-5222
"""
# 용법용량
if dosage: # 네트워크 프린터로 인쇄 (pos_printer 사용)
printer.text("-" * 42 + "\n") from pos_printer import print_text
printer.set(bold=True)
printer.text("▶ 용법용량\n") result = print_text(message, cut=True)
printer.set(bold=False)
for line in wrap_text(dosage[:400]): # 최대 400자 if result:
printer.text(f" {line}\n")
printer.text("\n")
# 주의사항
if precautions:
printer.text("-" * 42 + "\n")
printer.set(bold=True)
printer.text("▶ 주의사항\n")
printer.set(bold=False)
for line in wrap_text(precautions[:300]): # 최대 300자
printer.text(f" {line}\n")
printer.text("\n")
# 푸터
printer.set(align='center')
printer.text("=" * 42 + "\n")
printer.text("청 춘 약 국\n")
printer.text("Tel: 033-481-5222\n\n")
# 커팅
printer.cut()
printer.close()
return jsonify({'success': True, 'message': '동물약 안내서 인쇄 완료'}) return jsonify({'success': True, 'message': '동물약 안내서 인쇄 완료'})
else:
except Exception as e: return jsonify({'success': False, 'error': '프린터 출력 실패'}), 500
logging.error(f"인쇄 오류: {e}")
try:
printer.close()
except:
pass
return jsonify({'success': False, 'error': f'인쇄 오류: {str(e)}'}), 500
except Exception as e: except Exception as e:
logging.error(f"동물약 정보 인쇄 API 오류: {e}") logging.error(f"동물약 정보 인쇄 API 오류: {e}")