求助!文件打印

遇到了问题?请先进行搜索(中文和英文),然后在此提问

Moderators: tmplinshi, arcticir

ykwong
Posts: 2
Joined: 28 Nov 2018, 04:04

求助!文件打印

28 Nov 2018, 04:14

请问有什么代码可以让指定打印机打印指定的文件?
garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: 求助!文件打印

09 Dec 2018, 10:52

PRINTER
https://www.google.com/search?q=site%3A ... er+command
;- How to print from Autohotkey
;- https://autohotkey.com/boards/viewtopic ... 76&t=59581

;- PRINTER some examples
;- https://www.robvanderwoude.com/2kprintcontrol.php

Code: Select all

;- How to print from Autohotkey 
;- https://autohotkey.com/boards/viewtopic.php?f=76&t=59581
;- https://autohotkey.com/boards/viewtopic.php?p=78205#p78205   user 'just me'

;- PRINTER some examples 
;- https://www.robvanderwoude.com/2kprintcontrol.php

f1=%a_scriptdir%\test55.txt
var1=Pantum M6600NW Series
var2=Samsung SCX-4200 Series (USB001)


;runwait,%comspec% /k RUNDLL32.EXE PRINTUI.DLL`,PrintUIEntry /f "result1.txt" /Xg /n "%var1%"       ;- Get printer settings saving results in a file
;runwait,%comspec% /c RUNDLL32.EXE PRINTUI.DLL`,PrintUIEntry /f "result2.txt" /Xg /n "%var1%",,hide ;- same hidden
runwait,%comspec% /k RUNDLL32.EXE PRINTUI.DLL`,PrintUIEntry /e /n "%var1%"                          ;- display preferences
runwait,%comspec% /k RUNDLL32.EXE PRINTUI.DLL`,PrintUIEntry /p /n "%var1%"                          ;- display properties
;runwait,%comspec% /k RUNDLL32.EXE PRINTUI.DLL`,PrintUIEntry /o /n "%var1%"                         ;- display queue
;runwait,%comspec% /k RUNDLL32.EXE PRINTUI.DLL`,PrintUIEntry /s /n "%var1%"                         ;- display server
return

;- print file (f1) but must click on printer
ifexist,%f1%
runwait,%comspec% /k RUNDLL32.EXE MSHTML.DLL`,PrintHTML "%f1%" /y /n "%var1%"
return

/*
ifexist,%f1%
{
;TrayTip,Name » %var1%,Now printing %f1%, 10, 17
;sleep,2000
RunWait,%comspec% /c RUNDLL32.exe PRINTUI.DLL`,PrintUIEntry /y /n "%var1%",,hide
Run, notepad /p "%f1%",,hide
return
}
return
*/
;==================================================================================

existing printers :

Code: Select all

;- printerx
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

out=
for k, v in EnumPrinters()
 {
 out= % out "#" k "`nFlags: " v.Flags "`nDescription: " v.Description "`nName: " v.Name "`nComment: " v.Comment . "`n`n"
 tmp:=v.Name
 Gui, Add, text, xm vq%A_Index%,
 q%A_Index%=% v.Name
 b%A_Index%=% v.Name
 c%A_Index%=% v.Name
 r%A_Index%=% v.Name
 Gui, Add, text, xp+50 yp+5,% v.Name
}
msgbox, % out
fileappend,%out%,MyPrinters.txt
gui, add, text,,
Gui, Show,, Print Test v1.1
return
Guiclose:
exitapp

EnumPrinters() {
 DllCall("Winspool.drv\EnumPrinters", "UInt", 0x00000002, "Ptr", 0, "UInt", 1, "Ptr", 0, "UInt", 0, "UIntP", Size, "UIntP", 0)
 , VarSetCapacity(PRINTER_INFO_1, Size * 2, 0)
 , DllCall("Winspool.drv\EnumPrintersW", "UInt", 0x00000002, "Ptr", 0, "UInt", 1, "Ptr", &PRINTER_INFO_1, "UInt", Size, "UIntP", 0, "UIntP", Count)
 Offset := A_PtrSize=4?-16:-32, List := []
 Loop, % Count {
  Info := {}, Offset += A_PtrSize=4?16:32
  , Info.Flags := NumGet(PRINTER_INFO_1, Offset, "UInt")
  , Info.Description := StrGet(NumGet(PRINTER_INFO_1, Offset+A_PtrSize))
  , Info.Name := StrGet(NumGet(PRINTER_INFO_1, Offset+(A_PtrSize*2)))
  , Info.Comment := StrGet(NumGet(PRINTER_INFO_1, Offset+(A_PtrSize*3)))
  , List.Push(Info)
 } return List
}
;=========================================================================
is default printer ON / OFF (?)

Code: Select all

;-------- https://autohotkey.com/boards/viewtopic.php?f=5&t=32508 ---
;- http://www.robvanderwoude.com/2kprintcontrol.php

;- is default printer ON/OFF (?)
f1=%a_scriptdir%\PrtExist.txt
ifexist,%f1%
  filedelete,%f1%

;- get default printers name
If A_OSVersion in WIN_NT4,WIN_95,WIN_98,WIN_ME
  RegRead, var, HKLM\Config\0001\System\CurrentControlSet\Control\Print\Printers, Default
Else
  RegRead, var, HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows, Device
StringSplit, var, var, `,

runwait,%comspec% /c RUNDLL32.EXE PRINTUI.DLL`,PrintUIEntry /Xg /n "%var1%" /f "%F1%" /q,,hide
fileread,aa,%f1%
if aa contains WorkOffline
  msgbox,YOUR default PRINTER:`n%var1%`n`nis OFF-LINE
else
  msgbox,YOUR default PRINTER:`n%var1%`n`nis ON-LINE
aa=
ifexist,%f1%
  filedelete,%f1%
exitapp
;==============================================================
ykwong
Posts: 2
Joined: 28 Nov 2018, 04:04

Re: 求助!文件打印

09 Dec 2018, 20:30

Thanks...

Return to “请求帮助”

Who is online

Users browsing this forum: No registered users and 51 guests