gpt4 book ai didi

Python27 - 在 Windows 10 上我怎么知道打印纸尺寸是 50.8mm x 25.4mm?

转载 作者:可可西里 更新时间:2023-11-01 10:33:54 24 4
gpt4 key购买 nike

我在使用 A4 打印机的 Windows 上有这段代码。但是我有一台非常小的打印机,当我打印一些东西时它什么也打印不出来,只是把票推出。

enter image description here

尝试0:

import win32ui
X=0; Y=0
input_string = "Print 1234 test"
multi_line_string = input_string.split()
hDC = win32ui.CreateDC ()
hDC.CreatePrinterDC ('Dymo label printer')
hDC.StartDoc ('FILE NAME FILE NAME')
hDC.StartPage ()
for line in multi_line_string:
hDC.TextOut(X,Y,line)
#Y += 100
hDC.EndPage ()
hDC.EndDoc ()

TRY1:无法像以前一样打印:https://msdn.microsoft.com/en-us/library/windows/desktop/dd319099(v=vs.85).aspx

import win32ui
import win32con
import win32print
import win32gui

X=0
Y=0
input_string = "A390"

printer = win32print.GetDefaultPrinter()
hprinter = win32print.OpenPrinter(printer)
devmode = win32print.GetPrinter(hprinter, 2)["pDevMode"]

# change paper size and orientation
# constants are available here:
# http://msdn.microsoft.com/library/default.asp?
# url=/library/en-us/intl/nls_Paper_Sizes.asp
# number 10 envelope is 20
devmode.PaperSize = 20
# 1 = portrait, 2 = landscape
devmode.Orientation = 1

hdc = win32gui.CreateDC("WINSPOOL", printer, devmode)
dc = win32ui.CreateDCFromHandle(hdc)
dc.StartDoc ('test')
dc.StartPage ()
dc.TextOut(X,Y,input_string)
#for line in multi_line_string:
#hDC.TextOut(X,Y,line)
dc.EndPage ()
dc.EndDoc ()

尝试 2:失败

import win32ui
import win32con
import win32print
import win32gui

printer = win32print.GetDefaultPrinter()
hprinter = win32print.OpenPrinter(printer)
devmode = win32print.GetPrinter(hprinter, 2)["pDevMode"]
devmode.PaperSize = 20
devmode.Orientation = 2

hDC = win32gui.CreateDC ("WINSPOOL", printer, devmode)
dc = win32ui.CreateDCFromHandle(hDC)
dc.StartDoc ('test')
dc.StartPage ()

#hDC.SetMapMode(MM_TEXT) # ERROR no MM_TEXT found...
font = win32ui.CreateFont({
"name": "Lucida Console",
"height": 50,
"weight": 50,
})
win32print.DocumentProperties(0, hprinter, '300LN1', None, None, 5)
dc.SelectObject(font)
dc.TextOut(10,10,"TEST...")
dc.TextOut(10,-10,"TEST..")

dc.EndPage ()
dc.EndDoc ()

尝试 3:失败

import win32ui
import win32print
import win32con

INCH = 1440

hDC = win32ui.CreateDC ()
hDC.CreatePrinterDC (win32print.GetDefaultPrinter ())
hDC.StartDoc ("Test doc")
hDC.StartPage ()
hDC.SetMapMode (win32con.MM_TWIPS)
hDC.DrawText ("TEST", (0, INCH * -1, INCH * 8, INCH * -2), win32con.DT_CENTER)
hDC.EndPage ()
hDC.EndDoc ()

最佳答案

你应该试试这个:

#MM_TEXT= Each logical unit is mapped to one device pixel. Positive x is to the right; positive y is down. OR to draw MM_TWIPS see link
hDC.SetMapMode(MM_TEXT)
font = win32ui.CreateFont({
"name": "Lucida Console",
"height": 10,
"weight": 20,
})
win32print.DocumentProperties(0, pHandle, '300LN1', None, None, 5)
hDC.SelectObject(font)
#First print this test to know if it is inverted as user say it
# Also don't forget to keep **LONG TEXT TEST** to have chance to see it if not well placed.
hDC.TextOut(10,10,"This is a Test/ This is a second test...................")
hDC.TextOut(10,-10,"This is the bottom Test/ This is a second bottom test.................")

来自:

http://newcenturycomputers.net/projects/pythonicwindowsprinting.html

https://msdn.microsoft.com/fr-fr/library/windows/desktop/dd162980(v=vs.85).aspx

关于Python27 - 在 Windows 10 上我怎么知道打印纸尺寸是 50.8mm x 25.4mm?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38178454/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com