Fix orientation: remove landscape flag from SumatraPDF (PDF already landscape), remove win32print orientation interference
This commit is contained in:
@@ -413,37 +413,23 @@ def print_to_printer(printer_name, file_path):
|
|||||||
r"C:\Program Files (x86)\SumatraPDF\SumatraPDF.exe",
|
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:
|
for sumatra_path in sumatra_paths:
|
||||||
if os.path.exists(sumatra_path):
|
if os.path.exists(sumatra_path):
|
||||||
try:
|
try:
|
||||||
print(f"Using SumatraPDF: {sumatra_path}")
|
print(f"Using SumatraPDF: {sumatra_path}")
|
||||||
print(f"Sending to printer: {printer_name}")
|
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([
|
result = subprocess.run([
|
||||||
sumatra_path,
|
sumatra_path,
|
||||||
"-print-to",
|
"-print-to",
|
||||||
printer_name,
|
printer_name,
|
||||||
file_path,
|
file_path,
|
||||||
"-print-settings",
|
"-print-settings",
|
||||||
"noscale,landscape", # preserve dimensions + force landscape
|
"noscale",
|
||||||
"-silent",
|
"-silent",
|
||||||
"-exit-when-done"
|
"-exit-when-done"
|
||||||
], check=False, creationflags=subprocess.CREATE_NO_WINDOW,
|
], check=False, creationflags=subprocess.CREATE_NO_WINDOW,
|
||||||
|
|||||||
Reference in New Issue
Block a user