Compare commits
2 Commits
7437c547ec
...
cbf324eb76
| Author | SHA1 | Date | |
|---|---|---|---|
| cbf324eb76 | |||
| 71558cc983 |
BIN
dist/LabelPrinter.exe
vendored
BIN
dist/LabelPrinter.exe
vendored
Binary file not shown.
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user