From 71558cc983dfd40d61abbd45146f1959421a14d5 Mon Sep 17 00:00:00 2001 From: adaptronic-label printer final Date: Mon, 23 Feb 2026 13:39:27 +0200 Subject: [PATCH] Fix orientation: remove landscape flag from SumatraPDF (PDF already landscape), remove win32print orientation interference --- print_label.py | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/print_label.py b/print_label.py index e9482dd..3114d9b 100644 --- a/print_label.py +++ b/print_label.py @@ -413,37 +413,23 @@ def print_to_printer(printer_name, file_path): r"C:\Program Files (x86)\SumatraPDF\SumatraPDF.exe", ]) - # Set printer to highest quality / landscape before sending job - if WIN32_AVAILABLE: - try: - import win32print - hPrinter = win32print.OpenPrinter(printer_name) - try: - props = win32print.GetPrinter(hPrinter, 2) - dm = props['pDevMode'] - if dm: - dm.Orientation = 2 # DMORIENT_LANDSCAPE - dm.PrintQuality = -4 # DMRES_HIGH (highest DPI) - dm.YResolution = -4 # also set Y res - win32print.SetPrinter(hPrinter, 2, props, 0) - print("Printer set to landscape + high quality") - finally: - win32print.ClosePrinter(hPrinter) - except Exception as qe: - print(f"Could not configure printer quality/orientation: {qe}") - for sumatra_path in sumatra_paths: if os.path.exists(sumatra_path): try: print(f"Using SumatraPDF: {sumatra_path}") print(f"Sending to printer: {printer_name}") + # IMPORTANT: The PDF is already landscape (35mm wide x 25mm tall). + # Do NOT add "landscape" to print-settings — it would rotate an + # already-landscape PDF 90° again, printing it portrait. + # "noscale" alone tells SumatraPDF to honour the PDF page size + # exactly and not fit/stretch it to the printer paper. result = subprocess.run([ sumatra_path, "-print-to", printer_name, file_path, "-print-settings", - "noscale,landscape", # preserve dimensions + force landscape + "noscale", "-silent", "-exit-when-done" ], check=False, creationflags=subprocess.CREATE_NO_WINDOW,