fix
This commit is contained in:
parent
8e049ab033
commit
a01c16982a
|
@ -86,7 +86,7 @@ class SnPost:
|
|||
return
|
||||
|
||||
menu = (MenuItem('退出', self.close), MenuItem('查看日志', self.log))
|
||||
image = Image.open("favicon.ico")
|
||||
image = Image.open("001.ico")
|
||||
title = "打印机"
|
||||
self.icon = pystray.Icon(title, image, "打印机", menu)
|
||||
threading.Thread(target=self.icon.run, daemon=True).start()
|
||||
|
@ -96,12 +96,11 @@ class SnPost:
|
|||
def pdf_printer():
|
||||
if request.method == 'OPTIONS': # 跨域请求预检
|
||||
return jsonify({"message": "OK"}), 200
|
||||
# if 'file' not in request.files:
|
||||
# return jsonify({"error_message": "No file part", "error_code": 400}), 400
|
||||
file = request.files['file']
|
||||
printer_name = request.form.get('printer_name', None)
|
||||
# Save the file temporarily
|
||||
temp_pdf_path = os.path.join(os.path.dirname(__file__), 'temp_pdf.pdf')
|
||||
logger.info(f"Saving file to {temp_pdf_path}")
|
||||
|
||||
try:
|
||||
# Read the PDF binary
|
||||
|
@ -109,7 +108,8 @@ def pdf_printer():
|
|||
if printer_name:
|
||||
win32print.OpenPrinter(printer_name)
|
||||
win32print.SetDefaultPrinter(printer_name)
|
||||
win32print.GetDefaultPrinter()
|
||||
else:
|
||||
return jsonify({"error_message": "打印机名称不正确","error_code": "printer_name_error"}), 400
|
||||
|
||||
win32api.ShellExecute(
|
||||
0,
|
||||
|
@ -121,6 +121,7 @@ def pdf_printer():
|
|||
)
|
||||
except Exception as e:
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
print(traceback.format_exc())
|
||||
return jsonify({"error_message": str(e), "error_code": "print_failed"}), 500
|
||||
finally:
|
||||
|
@ -145,32 +146,35 @@ def save_pdf_from_binary(pdf_binary, file_path):
|
|||
def str_printer():
|
||||
if request.method == 'OPTIONS': # 跨域请求预检
|
||||
return jsonify({"message": "OK"}), 200
|
||||
print_commands = request.json.get('print_commands', None)
|
||||
print_name = request.json.get('print_name', None)
|
||||
print(print_commands)
|
||||
print_commands = request.json.get('printer_commands', None)
|
||||
print_name = request.json.get('printer_name', None)
|
||||
tsclibrary = ctypes.WinDLL(".//TSCLIB.dll")
|
||||
if print_name:
|
||||
logger.info("打印机名称: %s", print_name)
|
||||
tsclibrary.openportW(print_name)
|
||||
else:
|
||||
print_name = win32print.GetDefaultPrinter()
|
||||
tsclibrary.openportW(print_name)
|
||||
logger.error("打印机名称无效")
|
||||
return jsonify({"error_message": "打印机名称无线","error_code": "printer_name_error"}), 400
|
||||
tsclibrary.clearbuffer()
|
||||
for item in print_commands:
|
||||
if 'WINTEXT' in item:
|
||||
item_list = item.replace('WINTEXT ', '').split(',')
|
||||
tsclibrary.windowsfontW(
|
||||
item_list[0],
|
||||
item_list[1],
|
||||
item_list[2],
|
||||
item_list[3],
|
||||
item_list[4],
|
||||
item_list[5],
|
||||
item_list[6],
|
||||
item_list[7])
|
||||
else:
|
||||
tsclibrary.sendcommandW(item)
|
||||
print(item, "33333")
|
||||
tsclibrary.closeport()
|
||||
try:
|
||||
for item in print_commands:
|
||||
if 'WINTEXT' in item:
|
||||
item_list = item.replace('WINTEXT ', '').split(',')
|
||||
tsclibrary.windowsfontW(
|
||||
item_list[0],
|
||||
item_list[1],
|
||||
item_list[2],
|
||||
item_list[3],
|
||||
item_list[4],
|
||||
item_list[5],
|
||||
item_list[6],
|
||||
item_list[7])
|
||||
else:
|
||||
tsclibrary.sendcommandW(item)
|
||||
tsclibrary.closeport()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
logger.error("打印错误: %s", str(e))
|
||||
|
||||
return jsonify({}), 200
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ exe = EXE(
|
|||
upx=True,
|
||||
upx_exclude=[],
|
||||
runtime_tmpdir=None,
|
||||
console=True,
|
||||
console=False,
|
||||
disable_windowed_traceback=False,
|
||||
argv_emulation=False,
|
||||
target_arch=None,
|
||||
|
|
BIN
favicon.ico
BIN
favicon.ico
Binary file not shown.
Before Width: | Height: | Size: 17 KiB |
|
@ -0,0 +1,9 @@
|
|||
[2024-07-23 14:22:33,040] [PrintAgent.py:157] [ERROR]- 打印机名称无效
|
||||
[2024-07-23 14:22:41,597] [PrintAgent.py:157] [ERROR]- 打印机名称无效
|
||||
[2024-07-23 14:23:38,476] [PrintAgent.py:157] [ERROR]- 打印机名称无效
|
||||
[2024-07-23 14:26:43,987] [PrintAgent.py:157] [ERROR]- 打印机名称无效
|
||||
[2024-07-23 14:26:49,117] [PrintAgent.py:157] [ERROR]- 打印机名称无效
|
||||
[2024-07-23 14:44:09,522] [PrintAgent.py:156] [ERROR]- 打印机名称无效
|
||||
[2024-07-23 14:45:04,932] [PrintAgent.py:157] [ERROR]- 打印机名称无效
|
||||
[2024-07-23 14:46:16,085] [PrintAgent.py:154] [INFO]- 打印机名称: GP-3150TN
|
||||
[2024-07-23 14:47:39,217] [PrintAgent.py:153] [INFO]- 打印机名称: GP-3150TN
|
Loading…
Reference in New Issue