""" Dump the full DEVMODE of the PT-E560BT driver. The printed length is far shorter than the page we send, which suggests the driver is cropped or scaled by a setting of its own. This prints every field that could cause that, so the behaviour can be explained rather than guessed. """ import win32print PRINTER = "Brother PT-E560BT" ORIENTATION = {1: "portrait", 2: "landscape"} FIELDS_OF_INTEREST = [ "PaperSize", "PaperLength", "PaperWidth", "Orientation", "Scale", "Copies", "DefaultSource", "PrintQuality", "Color", "Duplex", "TTOption", "Collate", "FormName", "LogPixels", "BitsPerPel", "Nup", "DisplayFlags", "DisplayFrequency", "ICMMethod", "ICMIntent", "MediaType", "DitherType", "Reserved1", "Reserved2", "PanningWidth", "PanningHeight", ] def main() -> int: info = win32print.GetPrinter(win32print.OpenPrinter(PRINTER), 2) dm = info.get("pDevMode") print(f"Printer : {PRINTER}") print(f"Driver : {info.get('pDriverName')}") print(f"Port : {info.get('pPortName')}") print(f"\nDEVMODE size : {dm.Size} bytes") print(f"DriverExtra : {dm.DriverExtra} bytes") print(f"Fields set (bitset): 0x{dm.Fields:x}") print("\nFields of interest:") for name in FIELDS_OF_INTEREST: if not hasattr(dm, name): continue try: value = getattr(dm, name) except Exception as exc: # noqa: BLE001 print(f" {name:<18}: ") continue extra = "" if name == "Orientation": extra = f" ({ORIENTATION.get(value, '?')})" elif name in ("PaperLength", "PaperWidth") and isinstance(value, int): extra = f" ({value / 10:.1f} mm)" print(f" {name:<18}: {value}{extra}") # Any other integer attributes the struct exposes. print("\nAll remaining numeric fields:") shown = set(FIELDS_OF_INTEREST) for name in sorted(dir(type(dm))): if name.startswith("_") or name in shown: continue try: value = getattr(dm, name) except Exception: # noqa: BLE001 continue if isinstance(value, int) and value != 0: print(f" {name:<20}: {value}") # Explain the relationship between page, printable area and paper length. print("\nInterpretation:") pl = dm.PaperLength / 10 pw = dm.PaperWidth / 10 print(f" paper wxh as stored : {pw:.1f} x {pl:.1f} mm " f"(orientation {ORIENTATION.get(dm.Orientation, '?')})") if dm.Orientation == 2: print(f" rotated for printing: {pl:.1f} mm along tape x {pw:.1f} mm across") print(f" dmScale : {dm.Scale}% (100 = no driver scaling)") return 0 if __name__ == "__main__": raise SystemExit(main())