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
try: {pg_product_name}
# 헤더 """
printer.set(align='center', bold=True, double_height=True) if company:
printer.text("🐾 동물약 안내서\n") message += f"제조: {company}\n"
printer.set(align='center', bold=False, double_height=False)
printer.text("=" * 42 + "\n\n")
# 제품명 if ingredient and ingredient != 'NaN':
printer.set(align='center', bold=True) message += f"""
printer.text(f"{pg_product_name}\n") {THIN}
printer.set(bold=False) 주성분
if company: """
printer.text(f"제조: {company}\n") for line in wrap_text(ingredient, 46):
printer.text("\n") message += f" {line}\n"
# 주성분 if efficacy:
if ingredient and ingredient != 'NaN': message += f"""
printer.set(align='left') {THIN}
printer.text("-" * 42 + "\n") 효능효과
printer.set(bold=True) """
printer.text("▶ 주성분\n") for line in wrap_text(efficacy[:400], 46):
printer.set(bold=False) message += f" {line}\n"
for line in wrap_text(ingredient):
printer.text(f" {line}\n")
printer.text("\n")
# 효능효과 if dosage:
if efficacy: message += f"""
printer.set(align='left') {THIN}
printer.text("-" * 42 + "\n") 용법용량
printer.set(bold=True) """
printer.text("▶ 효능효과\n") for line in wrap_text(dosage[:500], 46):
printer.set(bold=False) message += f" {line}\n"
for line in wrap_text(efficacy[:300]): # 최대 300자
printer.text(f" {line}\n")
printer.text("\n")
# 용법용량 if precautions:
if dosage: message += f"""
printer.text("-" * 42 + "\n") {THIN}
printer.set(bold=True) 주의사항
printer.text("▶ 용법용량\n") """
printer.set(bold=False) for line in wrap_text(precautions[:400], 46):
for line in wrap_text(dosage[:400]): # 최대 400자 message += f" {line}\n"
printer.text(f" {line}\n")
printer.text("\n")
# 주의사항 message += f"""
if precautions: {LINE}
printer.text("-" * 42 + "\n")
printer.set(bold=True) Tel: 033-481-5222
printer.text("▶ 주의사항\n") """
printer.set(bold=False)
for line in wrap_text(precautions[:300]): # 최대 300자
printer.text(f" {line}\n")
printer.text("\n")
# 푸터 # 네트워크 프린터로 인쇄 (pos_printer 사용)
printer.set(align='center') from pos_printer import print_text
printer.text("=" * 42 + "\n")
printer.text("청 춘 약 국\n")
printer.text("Tel: 033-481-5222\n\n")
# 커팅 result = print_text(message, cut=True)
printer.cut()
printer.close()
if result:
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}")