1

I want to print a file to the continuous paper using win32print in Python, but I have a problem in the set of the paper size .. When I following the code from: here the paper size always use A4 paper , I changed the paper size and the form name but nothing changed.

import win32print
import win32ui
import win32con
devmode.PaperSize = 50
devmode.PaperLength = 50
devmode.PaperWidth = 50
devmode.Orientation = 1
printer = win32print.GetDefaultPrinter()
hprinter = win32print.OpenPrinter(printer)
devmode = win32print.GetPrinter(hprinter, 2)["pDevMode"]
devmode.FormName = "Legal"
devmode.PaperSize = win32con.DMPAPER_9X11
devmode.PaperLength = 20
devmode.PrintQuality = 120
devmode.Orientation = 1
hDC = win32ui.CreateDC()
hDC.CreatePrinterDC(win32print.GetDefaultPrinter())
hDC.StartDoc('test')
hDC.StartPage()
scale_factor = 20
font = win32ui.CreateFont({
    "name": "Monospaced",
    # "name": "Times New Roman",
    "height": 20,
    "weight": 20,
})
hDC.SelectObject(font)
hDC.TextOut(300, 0, "TESTING ...")

hDC.EndPage()
hDC.EndDoc()

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.