From 097bc4c84f669f08684727f944790836e455e7bf Mon Sep 17 00:00:00 2001 From: thug0bin Date: Wed, 4 Mar 2026 19:20:26 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=8F=99=EB=AC=BC=EC=95=BD=20=EC=95=88?= =?UTF-8?q?=EB=82=B4=EC=84=9C=20=EC=9D=B8=EC=87=84=EB=A5=BC=20=EB=84=A4?= =?UTF-8?q?=ED=8A=B8=EC=9B=8C=ED=81=AC=20=ED=94=84=EB=A6=B0=ED=84=B0?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - USB 프린터에서 네트워크 프린터(192.168.0.174:9100)로 변경 - pos_printer.print_text() 함수 사용 (특이사항 인쇄와 동일 방식) - 80mm 프린터 기준 48자 레이아웃 --- backend/app.py | 143 ++++++++++++++++++++----------------------------- 1 file changed, 59 insertions(+), 84 deletions(-) diff --git a/backend/app.py b/backend/app.py index a097cec..9335cc9 100644 --- a/backend/app.py +++ b/backend/app.py @@ -6504,93 +6504,68 @@ def api_animal_drug_info_print(): dosage = strip_html(row.dosage_instructions) precautions = strip_html(row.precautions) - # ESC/POS 인쇄 데이터 생성 - from escpos.printer import Usb + # 80mm 프린터 = 48자 기준 + LINE = "=" * 48 + THIN = "-" * 48 - # 프린터 연결 (아침에 설정한 영수증 프린터) - try: - # POS 프린터 (VID/PID 확인 필요) - printer = Usb(0x0483, 0x5743, profile="default") - except Exception as e: - logging.error(f"프린터 연결 실패: {e}") - return jsonify({'success': False, 'error': f'프린터 연결 실패: {str(e)}'}), 500 + # 텍스트 메시지 생성 + message = f""" +{LINE} + 🐾 동물약 안내서 +{LINE} + +{pg_product_name} +""" + if company: + message += f"제조: {company}\n" - try: - # 헤더 - printer.set(align='center', bold=True, double_height=True) - printer.text("🐾 동물약 안내서\n") - printer.set(align='center', bold=False, double_height=False) - printer.text("=" * 42 + "\n\n") - - # 제품명 - printer.set(align='center', bold=True) - printer.text(f"{pg_product_name}\n") - printer.set(bold=False) - if company: - printer.text(f"제조: {company}\n") - printer.text("\n") - - # 주성분 - if ingredient and ingredient != 'NaN': - printer.set(align='left') - printer.text("-" * 42 + "\n") - printer.set(bold=True) - printer.text("▶ 주성분\n") - printer.set(bold=False) - for line in wrap_text(ingredient): - printer.text(f" {line}\n") - printer.text("\n") - - # 효능효과 - if efficacy: - printer.set(align='left') - printer.text("-" * 42 + "\n") - printer.set(bold=True) - printer.text("▶ 효능효과\n") - printer.set(bold=False) - for line in wrap_text(efficacy[:300]): # 최대 300자 - printer.text(f" {line}\n") - printer.text("\n") - - # 용법용량 - if dosage: - printer.text("-" * 42 + "\n") - printer.set(bold=True) - printer.text("▶ 용법용량\n") - printer.set(bold=False) - for line in wrap_text(dosage[:400]): # 최대 400자 - 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() - + if ingredient and ingredient != 'NaN': + message += f""" +{THIN} +▶ 주성분 +""" + for line in wrap_text(ingredient, 46): + message += f" {line}\n" + + if efficacy: + message += f""" +{THIN} +▶ 효능효과 +""" + for line in wrap_text(efficacy[:400], 46): + message += f" {line}\n" + + if dosage: + message += f""" +{THIN} +▶ 용법용량 +""" + for line in wrap_text(dosage[:500], 46): + message += f" {line}\n" + + if precautions: + message += f""" +{THIN} +▶ 주의사항 +""" + for line in wrap_text(precautions[:400], 46): + message += f" {line}\n" + + message += f""" +{LINE} + 청 춘 약 국 + Tel: 033-481-5222 +""" + + # 네트워크 프린터로 인쇄 (pos_printer 사용) + from pos_printer import print_text + + result = print_text(message, cut=True) + + if result: return jsonify({'success': True, 'message': '동물약 안내서 인쇄 완료'}) - - except Exception as e: - logging.error(f"인쇄 오류: {e}") - try: - printer.close() - except: - pass - return jsonify({'success': False, 'error': f'인쇄 오류: {str(e)}'}), 500 + else: + return jsonify({'success': False, 'error': '프린터 출력 실패'}), 500 except Exception as e: logging.error(f"동물약 정보 인쇄 API 오류: {e}")