Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using windo printer
#1
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")
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to send file to printer with no results. chob_thomas 2 3,265 Dec-21-2022, 07:12 AM
Last Post: Pedroski55
  How do you marshal the default printer setup to print? hammer 0 1,251 May-29-2022, 02:54 PM
Last Post: hammer
  Can you print a string variable to printer hammer 2 1,894 Apr-30-2022, 11:48 PM
Last Post: hammer
  Printing to a printer connected to pi 4 alan 2 2,382 Oct-04-2020, 10:08 PM
Last Post: alan
  python-printer-escpos 0.0.3 ERROR neethuvp 1 3,632 Nov-12-2019, 12:20 PM
Last Post: Larz60+
  Is this possible in Python? Auto-Send-to-printer on script run? pcsailor 8 16,689 Jul-19-2019, 09:33 AM
Last Post: perfringo
  Control a dot matrix printer Clement_2000 4 4,813 Jan-27-2019, 09:00 PM
Last Post: Clement_2000
  print a persian file by thermal printer and python-escpos mnodule gray 12 12,427 Nov-03-2017, 11:15 PM
Last Post: Larz60+
  printing a text file by python and thermal printer gray 6 20,420 Jul-30-2017, 05:56 AM
Last Post: buran
  python to install printer drivers automatic leoxucn 4 7,591 Jul-10-2017, 09:21 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020