Printing Using Python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Raja

    #1

    Printing Using Python

    Hi,
    Attached is the code . I want my program to save the current printer
    job properties and , when I reconnect the printer at a latter date , i
    need to print the saved job . Can you please help with my code ? How
    to print a document at a later stage and any errors in my code ?

    import win32ui
    import win32con

    myprinter_name = ""
    # get the name from your Printers folder

    printer_propert ies=[]

    def save():
    pHandle = win32print.Open Printer(myprint er_name)
    properties = win32print.GetP rinter(pHandle, 2)
    pDevModeObj = properties["pDevMode"]
    printer_propert ies.append(pDev ModeObj.FormNam e)
    printer_propert ies.append(pDev ModeObj.PaperSi ze)
    printer_propert ies.append(pDev ModeObj.Orienta tion)
    printer_propert ies.append(pDev ModeObj.Color)
    printer_propert ies.append(pDev ModeObj.Copies)
    printer_propert ies.append(pDev ModeObj.Default Source)
    win32print.Clos ePrinter(pHandl e)

    def apply():
    hprinter = win32print.Open Printer(myprint er_name)

    devmode = win32print.GetP rinter(hprinter , 2)["pDevMode"]
    devmode.FormNam e=printer_prope rties[0]
    devmode.PaperSi ze=printer_prop erties[1]
    devmode.Orienta tion=printer_pr operties[2]
    devmode.Color=p rinter_properti es[3]
    devmode.Copies= printer_propert ies[4]
    devmode.Default Source=printer_ properties[5]

    hdc = win32gui.Create DC("WinPrint",m yprinter_name,d evmode)
    dc = win32ui.CreateD CFromHandle(hdc )

    dc.StartDoc('My Python Document')
    dc.StartPage()
    dc.EndPage()
    dc.EndDoc()
    del dc


    You help is greatly appreciated.

    Thank You,
    Raja.

  • kyosohma@gmail.com

    #2
    Re: Printing Using Python

    On Apr 16, 2:13 pm, "Raja" <rokkamr...@gma il.comwrote:
    Hi,
    Attached is the code . I want my program to save the current printer
    job properties and , when I reconnect the printer at a latter date , i
    need to print the saved job . Can you please help with my code ? How
    to print a document at a later stage and any errors in my code ?
    >
    import win32ui
    import win32con
    >
    myprinter_name = ""
    # get the name from your Printers folder
    >
    printer_propert ies=[]
    >
    def save():
    pHandle = win32print.Open Printer(myprint er_name)
    properties = win32print.GetP rinter(pHandle, 2)
    pDevModeObj = properties["pDevMode"]
    printer_propert ies.append(pDev ModeObj.FormNam e)
    printer_propert ies.append(pDev ModeObj.PaperSi ze)
    printer_propert ies.append(pDev ModeObj.Orienta tion)
    printer_propert ies.append(pDev ModeObj.Color)
    printer_propert ies.append(pDev ModeObj.Copies)
    printer_propert ies.append(pDev ModeObj.Default Source)
    win32print.Clos ePrinter(pHandl e)
    >
    def apply():
    hprinter = win32print.Open Printer(myprint er_name)
    >
    devmode = win32print.GetP rinter(hprinter , 2)["pDevMode"]
    devmode.FormNam e=printer_prope rties[0]
    devmode.PaperSi ze=printer_prop erties[1]
    devmode.Orienta tion=printer_pr operties[2]
    devmode.Color=p rinter_properti es[3]
    devmode.Copies= printer_propert ies[4]
    devmode.Default Source=printer_ properties[5]
    >
    hdc = win32gui.Create DC("WinPrint",m yprinter_name,d evmode)
    dc = win32ui.CreateD CFromHandle(hdc )
    >
    dc.StartDoc('My Python Document')
    dc.StartPage()
    dc.EndPage()
    dc.EndDoc()
    del dc
    >
    You help is greatly appreciated.
    >
    Thank You,
    Raja.
    This sounds like a job for the pickle: http://docs.python.org/lib/module-pickle.html

    I would try "pickling" the printer_propert ies list and when you later
    need the pickled printer properties, unpickle them.

    Mike

    Comment

    • Roger Upole

      #3
      Re: Printing Using Python


      "Raja" <rokkamraja@gma il.comwrote:
      Hi,
      Attached is the code . I want my program to save the current printer
      job properties and , when I reconnect the printer at a latter date , i
      need to print the saved job . Can you please help with my code ? How
      to print a document at a later stage and any errors in my code ?
      >
      import win32ui
      import win32con
      >
      myprinter_name = ""
      # get the name from your Printers folder
      >
      printer_propert ies=[]
      >
      def save():
      pHandle = win32print.Open Printer(myprint er_name)
      properties = win32print.GetP rinter(pHandle, 2)
      pDevModeObj = properties["pDevMode"]
      printer_propert ies.append(pDev ModeObj.FormNam e)
      printer_propert ies.append(pDev ModeObj.PaperSi ze)
      printer_propert ies.append(pDev ModeObj.Orienta tion)
      printer_propert ies.append(pDev ModeObj.Color)
      printer_propert ies.append(pDev ModeObj.Copies)
      printer_propert ies.append(pDev ModeObj.Default Source)
      win32print.Clos ePrinter(pHandl e)
      >
      def apply():
      hprinter = win32print.Open Printer(myprint er_name)
      >
      devmode = win32print.GetP rinter(hprinter , 2)["pDevMode"]
      devmode.FormNam e=printer_prope rties[0]
      devmode.PaperSi ze=printer_prop erties[1]
      devmode.Orienta tion=printer_pr operties[2]
      devmode.Color=p rinter_properti es[3]
      devmode.Copies= printer_propert ies[4]
      devmode.Default Source=printer_ properties[5]
      >
      hdc = win32gui.Create DC("WinPrint",m yprinter_name,d evmode)
      dc = win32ui.CreateD CFromHandle(hdc )
      >
      dc.StartDoc('My Python Document')
      dc.StartPage()
      dc.EndPage()
      dc.EndDoc()
      del dc
      >
      >
      You help is greatly appreciated.
      >
      Thank You,
      Raja.
      >
      You should be able to pause the job using win32print.SetJ ob
      with JOB_CONTROL_PAU SE and resume it later using
      JOB_CONTROL_RES UME. That way you won't even have
      to store the print parameters yourself.

      hth
      Roger





      ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
      http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
      ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

      Comment

      Working...