[python-win32] win32print not printing
Marcelo Almeida
marcelo.cra at hotmail.com
Thu Jan 24 19:44:07 CET 2013
Hello everyone,
I am trying to print a string (not a file) with win32print api and I'm
using Tim Golden's
<http://timgolden.me.uk/python/win32_how_do_i/print.html> third
block of code (pasted below) as a testing example but without success.
There is just no errors and the printer spool show the file rapidly and
then nothing occurs. I could print using the ShellExecute but that's not
what I need, since it prints files (and file names to pages, which I also
don't want). Here is Tim Golden's snippet I'm using to test:
import os, sys
import win32print
printer_name = win32print.GetDefaultPrinter ()
#
# raw_data could equally be raw PCL/PS read from
# some print-to-file operation
#
if sys.version_info >= (3,):
raw_data = bytes ("This is a test", "utf-8")
else:
raw_data = "This is a test"
hPrinter = win32print.OpenPrinter (printer_name)
try:
hJob = win32print.StartDocPrinter (hPrinter, 1, ("test of raw data",
None, "RAW"))
try:
win32print.StartPagePrinter (hPrinter)
win32print.WritePrinter (hPrinter, raw_data)
win32print.EndPagePrinter (hPrinter)
finally:
win32print.EndDocPrinter (hPrinter)
finally:
win32print.ClosePrinter (hPrinter)
Thanks!
Marcelo.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20130124/b3486353/attachment.html>
More information about the python-win32
mailing list