printer problem

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
Speechless
User
Beiträge: 2
Registriert: Donnerstag 4. Oktober 2007, 19:23

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?
EyDu
User
Beiträge: 4881
Registriert: Donnerstag 20. Juli 2006, 23:06
Wohnort: Berlin

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)
Benutzeravatar
gerold
Python-Forum Veteran
Beiträge: 5555
Registriert: Samstag 28. Februar 2004, 22:04
Wohnort: Oberhofen im Inntal (Tirol)
Kontaktdaten:

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,
:-)
http://halvar.at | Kleiner Bascom AVR Kurs
Wissen hat eine wunderbare Eigenschaft: Es verdoppelt sich, wenn man es teilt.
Speechless
User
Beiträge: 2
Registriert: Donnerstag 4. Oktober 2007, 19:23

thank you very much, now work great! :D once again thank you
Antworten