diff --git a/backend/main.py b/backend/main.py index 9994676..7e393b9 100644 --- a/backend/main.py +++ b/backend/main.py @@ -566,6 +566,34 @@ async def api_evacuer_bourrage(): return {"succes": True, "message": msg} +@app.post("/api/imprimante/couper") +async def api_couper_papier(): + """Déclenche la coupe en envoyant un micro-job blanc (la K60 coupe après chaque impression).""" + import subprocess, tempfile, os + from PIL import Image + config = charger_config() + nom = config.get("impression", {}).get("imprimante", "Mitsubishi") + try: + # Image blanche 1x15cm (la plus petite possible pour la K60) + img = Image.new("RGB", (600, 1800), (255, 255, 255)) + tmp = tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) + img.save(tmp.name, "JPEG", quality=95, dpi=(300, 300)) + tmp.close() + r = subprocess.run( + ["lp", "-d", nom, "-n", "1", + "-o", "PageSize=w288h432-div2", + "-o", "StpiShrinkOutput=Crop", + tmp.name], + capture_output=True, text=True, timeout=15 + ) + os.unlink(tmp.name) + if r.returncode == 0: + return {"succes": True, "message": "Coupe lancée — le papier va être coupé"} + return {"succes": False, "message": f"Erreur : {r.stderr.strip() or r.stdout.strip()}"} + except Exception as e: + return {"succes": False, "message": str(e)} + + @app.post("/api/imprimante/reset-usb") async def api_reset_usb(): """Réinitialise la connexion USB de l'imprimante (unbind/rebind driver).""" diff --git a/frontend/index.html b/frontend/index.html index 61c29ae..dac236d 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -405,6 +405,7 @@