0

My program is to print some text using win32api with same printer. The code below works well on one of my win10 desktop(it means the text size, distance from text to edge, distance between lines are all good), but when I try it on another win10 laptop, the line7 and line8 are missing. It looks like the rest lines are cut while my page still has space for these lines.

The padding space from text to the paper edge is also changed when I use the program in this new lap top. How can I fix these problem?

import win32ui, win32con
multi_line_string = [line1, line2, line3, line4, line5, line6, line7, line8] # My text to print line by line
fontdata = {'name': 'Arial', 'weight': win32con.FW_NORMAL, 'height': 60, 'width': 17}
hDC = win32ui.CreateDC()
hDC.CreatePrinterDC('myprinter')
font = win32ui.CreateFont(fontdata)
hDC.SelectObject(font)
hDC.StartDoc('alex')
hDC.StartPage()
for line in multi_line_string:
    hDC.TextOut(X, Y, line)          
    Y += Y_distance
hDC.EndPage()
hDC.EndDoc()
dejanualex
  • 3,872
  • 6
  • 22
  • 37
toblKr
  • 141
  • 2
  • 13
  • You don't appear to be setting page size. Maybe the default page different on the machine that it doesn't work on? This would also explain the different margin. – SiHa Aug 11 '20 at 09:48
  • @SiHa I am using the same paper and printer, the paper is tag(100mm*800mm) for delivery. Which api is for the page size? Thank you – toblKr Aug 11 '20 at 09:52
  • Same paper and printer, different laptop (and default printer driver settings). I have no idea what api calls you need, sorry, just suggesting an area to investigate, hence I'm not posting an answer. https://stackoverflow.com/questions/38178454/python27-on-windows-10-how-can-i-tell-printing-paper-size-is-50-8mm-x-25-4mm may help – SiHa Aug 11 '20 at 10:01
  • More useful info here: http://timgolden.me.uk/python/win32_how_do_i/print.html – SiHa Aug 11 '20 at 11:06
  • I try this "Raw printable data: use win32print directly" from the link http://timgolden.me.uk/python/win32_how_do_i/print.html, but the printer is not working – toblKr Aug 11 '20 at 11:30

0 Answers0