Python Forum

Full Version: using windo printer
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
toshiba laptop, windows 7, python 3.4
errors using: pywin32

list of imports: sys, os, win32ui, win32print, win32con, #import win32api ?

    def paper_report(line_size, composit_print): 
   
    pHandle = win32print.GetDefaultPrinter () 
    printer = win32print.OpenPrinter(pHandle)
    assert printer
    
    raw_data = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    #raw_data = bytes(plaintext, 'UTF-8')
    #composit_print[0]    
    
    win32print.StartDocPrinter(pHandle, 1, "RAW")
    #assert win32print
     
    win32print.StartPagePrinter(printer)
        
    win32print.WritePrinter(printer, raw_data) 
    assert win32print.WritePrinter
    
    win32print.EndPagePrinter(printer)  
    
    win32print.EndDocPrinter(printer)
    win32print.ClosePrinter(printer) 
       
    return       
Error:
    TypeError: The object is not a PyHANDLE object
--------------------------------------------------------------------------------------
I have used many combos of pywin32 and got many errors. this last erreor was
generated by: win32print.StartDocPrinter(pHandle, 1, "RAW")
That doesn't look like the full error, there should be a line number and the previous few commands associated with it.
Also, there's not enough code to execute, nor is indentation correct.
I added code tags
Please correct and re-post
Thanks