def main(): global JOBS_INFO, EXIT if len(sys.argv) not in (2, 3, 4): print( "usage: %s /path/to/document.pdf [printer-name] [document-title]" % sys.argv[0]) return -3 filename = sys.argv[1] with open(filename, 'rb') as f: pdf_data = f.read() if len(sys.argv) == 2: from xpra.platform.win32.printing import get_printers printers = get_printers() printer_name = printers.keys()[0] if len(sys.argv) in (3, 4): printer_name = sys.argv[2] if len(sys.argv) == 4: title = sys.argv[3] else: title = os.path.basename(filename) import time from xpra.util import csv from xpra.log import Logger log = Logger("printing", "win32") #start a new thread before submitting the document, #because otherwise the job may complete before we can get its status from threading import Thread t = Thread(target=watch_print_job_status, name="watch print job status") t.daemon = True t.start() job_id = print_pdf(printer_name, title, pdf_data) if job_id < 0: return job_id #wait for job to end: job_status = None while True: job_info = JOBS_INFO.get(job_id, {}) log("job_info[%i]=%s", job_id, job_info) v = job_info.get("job_status") if v != job_status: log.info("print job status: %s", csv(v)) job_status = v if "OFFLINE" in job_status or "DELETING" in job_status: EXIT = True break time.sleep(1.0) return 0
def main(argv): import datetime if len(argv)==1: from xpra.platform.win32.printing import get_printers printers = get_printers() log("printers: %s", printers) printer_name = printers.keys()[0] elif len(argv)==2: printer_name = argv[1] else: log.error("usage: %s [printer-name]", argv[0]) return 1 title = "Test Page" log.warn("HELLO1") x = GDIPrinterContext(printer_name) log.warn("HELLO GDIPrinterContext: %s", x) with GDIPrinterContext(printer_name) as hdc: log("hdc=%s", hdc) docinfo = DOCINFO() docinfo.lpszDocName = LPCSTR("%s\0" % title) log("StartDocA(%#x, %s)", hdc, docinfo) r = StartDocA(hdc, pointer(docinfo)) if r<0: log.error("StartDocA failed: %i", r) return r log("StartDocA()=%i" % r) r = StartPage(hdc) if r<0: log.error("StartPage failed: %i", r) return r x, y = 100, 100 s = "Test Page printed at %s" % (datetime.datetime.now()) if not TextOutA(hdc, x, y, LPCSTR(s), len(s)): log.error("TextOutA failed") return 1 r = EndPage(hdc) if r<0: log.error("EndPage failed: %i", r) return r r = EndDoc(hdc) if r<0: log.error("EndDoc failed: %i" % r) return r log("EndDoc()=%i" % r) return 0
def main(): if len(sys.argv) not in (2, 3, 4): print("usage: %s /path/to/document.pdf [printer-name] [document-title]" % sys.argv[0]) return -3 filename = sys.argv[1] with open(filename, 'rb') as f: pdf_data = f.read() if len(sys.argv)==2: from xpra.platform.win32.printing import get_printers printers = get_printers() log("printers: %s", printers) printer_name = printers.keys()[0] if len(sys.argv) in (3, 4): printer_name = sys.argv[2] if len(sys.argv)==4: title = sys.argv[3] else: title = os.path.basename(filename) return print_pdf(printer_name, title, pdf_data)