Hans Becker
2015-06-10 18:48:16 UTC
Just about a month ago I started reading Learning Python by Mark Lutz.
It's a new paradigm for me. I have a whole bunch of old mainframe files
with carriage control characters as the 1st character in each line.
Well, a got a very simple script working except I need to be able to
print landscape on my pc printer. Does anyone by chance have sample code I
could cut and paste to print landscape? I'm running Windows 7 Pro and
Python 2.7
#prt1a is a copy of prt11
import os, sys, tempfile
import win32api, win32print
printer_name = win32print.GetDefaultPrinter ()
hPrinter = win32print.OpenPrinter (printer_name)
hJob = win32print.StartDocPrinter (hPrinter, 1, ('alfie', None, "RAW"))
win32print.StartPagePrinter (hPrinter)
for line in open('alf1'):
cc = line[0]
line = line[1:]
line = line.rstrip()
if cc == '1': line = '\f' + line
elif cc == ' ': line = '\n' + line
elif cc == '0': line = '\n\n' + line
elif cc == '-': line = '\n\n\n' + line
line = line + '\r' # takes care of the overprinting
win32print.WritePrinter(hPrinter, line)
win32print.WritePrinter(hPrinter,"\f")
win32print.EndPagePrinter (hPrinter)
win32print.EndDocPrinter (hPrinter)
win32print.ClosePrinter (hPrinter)
my test data 'alf1':
1 QWDDNNNDNDN
++2 /111111111
++2a XXXXXXXX11
3 ZDDDDNDNDNNN
++4 #/1111111111
++4a #XXXXXXXXX11
++4 b #WWWWWWWWWW1
5 MMMMMMNMMMMMMMMNMNNNNMNNNM
++6 IIIIII1IIIIIIII1I1111I111I
++6a IIIIII1IIIIIIII1I1111I111I
7 NNMNNNNNNNNNNNNNNNNNNNNNMM
++8 11I111111111111111111111II
9 ..........................
10 --------------------------
11 ;;;;;;;;
Thanks
Hans Becker
It's a new paradigm for me. I have a whole bunch of old mainframe files
with carriage control characters as the 1st character in each line.
Well, a got a very simple script working except I need to be able to
print landscape on my pc printer. Does anyone by chance have sample code I
could cut and paste to print landscape? I'm running Windows 7 Pro and
Python 2.7
#prt1a is a copy of prt11
import os, sys, tempfile
import win32api, win32print
printer_name = win32print.GetDefaultPrinter ()
hPrinter = win32print.OpenPrinter (printer_name)
hJob = win32print.StartDocPrinter (hPrinter, 1, ('alfie', None, "RAW"))
win32print.StartPagePrinter (hPrinter)
for line in open('alf1'):
cc = line[0]
line = line[1:]
line = line.rstrip()
if cc == '1': line = '\f' + line
elif cc == ' ': line = '\n' + line
elif cc == '0': line = '\n\n' + line
elif cc == '-': line = '\n\n\n' + line
line = line + '\r' # takes care of the overprinting
win32print.WritePrinter(hPrinter, line)
win32print.WritePrinter(hPrinter,"\f")
win32print.EndPagePrinter (hPrinter)
win32print.EndDocPrinter (hPrinter)
win32print.ClosePrinter (hPrinter)
my test data 'alf1':
1 QWDDNNNDNDN
++2 /111111111
++2a XXXXXXXX11
3 ZDDDDNDNDNNN
++4 #/1111111111
++4a #XXXXXXXXX11
++4 b #WWWWWWWWWW1
5 MMMMMMNMMMMMMMMNMNNNNMNNNM
++6 IIIIII1IIIIIIII1I1111I111I
++6a IIIIII1IIIIIIII1I1111I111I
7 NNMNNNNNNNNNNNNNNNNNNNNNMM
++8 11I111111111111111111111II
9 ..........................
10 --------------------------
11 ;;;;;;;;
Thanks
Hans Becker