Seite 1 von 1

printer problem

Verfasst: Donnerstag 4. Oktober 2007, 19:26
von Speechless
Hello

Please help me - I write code to read file and send to the printer...

Code: Alles auswählen

import win32print

f = open("C:/abc.txt","w")
f.write("linia1\n")
f.write("linia2\n")
f.write("linia3")
f.close()

y = open("C:/abc.txt","r")
ry = y.read()
y.close()

dane = ry

default_printer=win32print.GetDefaultPrinter() 

hprinter = win32print.OpenPrinter(default_printer)

a = win32print.StartDocPrinter(hprinter, 1, ('Testowy wydruk', None, None))

b = win32print.WritePrinter(hprinter, dane)

c = win32print.EndDocPrinter(hprinter) 

d = win32print.ClosePrinter(hprinter)
all works fine but printer print on page something like this:

linia1
.......linia2
..............linia3

I want:

linia1
linia2
linia3

How to fix this?

Verfasst: Donnerstag 4. Oktober 2007, 19:55
von EyDu
I think your printer needs a carriage-return-character to reset the cursor to the beginning of a line. So use "linia1\r\n" instead of "linia\n":

Code: Alles auswählen

dane = "linia1\r\nlinia2\r\nlinia3"

default_printer=win32print.GetDefaultPrinter() 

hprinter = win32print.OpenPrinter(default_printer)

a = win32print.StartDocPrinter(hprinter, 1, ('Testowy wydruk', None, None))

b = win32print.WritePrinter(hprinter, dane)

c = win32print.EndDocPrinter(hprinter) 

d = win32print.ClosePrinter(hprinter)

Re: printer problem

Verfasst: Donnerstag 4. Oktober 2007, 21:13
von gerold
Speechless hat geschrieben:Please help me - I write code to read file and send to the printer...
Hello Speechless!

Welcome!

If you open the file like this: ``y = open("C:/abc.txt","rb")``, Python doesn´t replace the lineendings "CrLf (\r\n)" by "Lf (\n)".

Regards,
:-)

Verfasst: Freitag 5. Oktober 2007, 06:49
von Speechless
thank you very much, now work great! :D once again thank you