Send output to printer

MRAB google at mrabarnett.plus.com
Wed Jun 25 09:41:04 EDT 2008


On Jun 25, 7:49 am, "Jorgen Bodde" <jorgen.maill... at gmail.com> wrote:
> Hi,
>
> It depends on how your printer can be accessed. Is there a driver for
> it? The most simple way might be using ShellExecute (under windows)
> but I found  no way to supress the print dialog.
>
> Another way is using win32com module and instantiate an IE automation
> object, which you feed a HTML page and issue a print. Be careful about
> printing too fast allow it 4-5 seconds to process or successive print
> jobs will fail.
>
> Here is a snippet of code to get you on your way;
>
> from win32com import client
> ie = client.Dispatch("InternetExplorer.Application")
> ie.Navigate(fn)      # fn = filename (to temp file) to print
> time.sleep(2)
> ie.ExecWB(6, 2)
> time.sleep(2)
> ie.Quit()
> ie = None
>
> For successive prints it is better to instantiate one IE object per
> multiple print jobs, but once done, release it and set it up again.
>
> - Jorgen
>
> On Wed, Jun 25, 2008 at 6:54 AM, ajak_yahoo <araza... at yahoo.com.my> wrote:
> > Need some help from you all,
>
> > I already manage to write a program to print a packaging label.
>
> > The output on screen is as below,
>
> > Part Number   :  PWEE1111AA
> > Quantity         :  100 pcs
> > Lot Number     :  10A2008
> > Customer        :  ABC Pte. Ltd.
>
> > My questions is how can I send this output to my Panasonic KX-P1121 dot
> > matric printer,
> > Is it a module that i can used, previously i wrote my program using foxpro
> > 2.6, i have no experience in python.
>
> > Regards,
> > Ajak
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
>

If it's connected to the PC's parallel printer port then you could try
writing to "LPT1:":

printer = open("LPT1:", "wb")
printer.write("Hello world!\r\n")
printer.close()

Note that in order to advance to the next line you'll need to write a
carriage return and linefeed ("\r\n"), as above.



More information about the Python-list mailing list