所以我找到了一个哥伦比亚大学的脚本,通过使用PDFXCVIEW从CMD进行打印。它是此程序的自动it Package 器。脚本需要1.25秒才能打印下一个文档,如果我在这1.25秒之前发送文档打印,它不会打印。有人能告诉我为什么以及如何解决这个延迟吗?脚本有一个我删除的多示例提示符。
代码如下:
# Region ;****Directives created by AutoIt3Wrapper_GUI****
# AutoIt3Wrapper_Icon=pdftoprinter.ico
# AutoIt3Wrapper_Outfile=d:\dropbox\PDFtoPrinter.exe
# AutoIt3Wrapper_Res_Description=PDFtoPrinter.exe
# AutoIt3Wrapper_Res_Fileversion=2.0.3.130
# AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
# AutoIt3Wrapper_Res_ProductName=PDFtoPrinter.exe
# AutoIt3Wrapper_Res_Language=1033
# AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
# AutoIt3Wrapper_Run_After=d:\dropbox\signfilesem.exe "%out%"
# EndRegion ;****Directives created by AutoIt3Wrapper_GUI****
# include <GUIConstantsEx.au3>
# include <Array.au3>
# include <Constants.au3>
# include <WinAPI.au3>
# include <APIErrorsConstants.au3>
# include <Misc.au3>
# include "GUIScrollbars_Ex.au3"
Global $msgTitle = "PDFtoPrinter.exe"
Global $specified = 0
Global $cli = 0
Global $debug = 0
Global $printername
Global $defaultprinter
Global $gh
Local $pth = @ScriptDir
Local $fn = @ScriptName
Local $noprinter = 0
Local $space = " "
Local $qt = Chr(34)
Local $pdffile = ""
Local $basestring = ""
Local $showselptr = 0
Local $pgvar = " "
Local $copies = 1
Local $focus = ""
Local $printstring
Opt("WinTitleMatchMode", -2)
If StringInStr($fn, "select") Then $showselptr = 1
If StringInStr($fn, "debug") Then $debug = 1
If StringInStr($fn, "cli") Then $cli = 1
Local $cmln = $CmdLine[0]
If $cmln = 0 Then
If $cli = 0 Then
MsgBox(0, $msgTitle, "Usage: PDFtoPrinter.exe [path\]filename.pdf [" & $qt & "printer name" & _
$qt & "] [pages=#-#] [copies=#] [focus=" & $qt & "Window title" & $qt & "] [/debug]" _
& @CRLF & @CRLF & "Use quotation marks around [path\]filename with spaces." _
& @CRLF & @CRLF & "Default printer is used unless printer name is specified." _
& @CRLF & @CRLF & "Rename to PDFtoPrinterSelect.exe for select-printer menu." _
& @CRLF & "(Menu does not appear if printer name is specified.)" _
& @CRLF & @CRLF & "Page range examples: 3 [or] 2-4,6,8-9 [or] 8- " _
& @CRLF & @CRLF & "focus= restores focus to specified window tirtle." _
& @CRLF & @CRLF & "/debug copies print command to Windows clipboard.", 30)
EndIf
Exit
EndIf
If $cmln >= 1 Then
Local $z1 = (StringLower($CmdLine[1]))
If StringRight($z1, 4) = ".pdf" Then
$pdffile = $z1
If StringInStr($pdffile, "\") = 0 Then ;; if filename has no path, add working directory to path
$pdffile = $pth & "\" & $pdffile
EndIf
EndIf
If $cmln >= 2 Then
For $x = 2 To $CmdLine[0]
If StringLower(StringLeft($CmdLine[$x], 6)) = "pages=" Then
$pgvar = "&" & $CmdLine[$x] & $qt & " "
If Not @Compiled Then ConsoleWrite("Pages: " & $pgvar & @LF)
ElseIf StringLower(StringLeft($CmdLine[$x], 7)) = "copies=" Then ; per Peter Mickle
$copies = (StringMid($CmdLine[$x], 8, -1))
If Not @Compiled Then ConsoleWrite("Copies: " & $copies & @LF)
If Not StringIsInt($copies) Then
If $cli = 0 Then
MsgBox(0, $msgTitle, "The copies= parameter must use an integer.")
EndIf
Exit
EndIf
ElseIf StringLower(StringLeft($CmdLine[$x], 6)) = "focus=" Then ; return Focus
$focus = (StringMid($CmdLine[$x], 7, -1))
If Not StringLeft($focus, 1) = Chr(34) Then $focus = Chr(34) & $focus
If Not StringRight($focus, 1) = Chr(34) Then $focus = $focus & Chr(34)
If Not @Compiled Then ConsoleWrite("$focus = " & $focus & @LF)
ElseIf $CmdLine[$x] = "/debug" Then
$debug = 1
Else
$printername = $CmdLine[$x]
$specified = 1
$showselptr = 0
EndIf
Next
EndIf
EndIf
If $pgvar = " " Then $pgvar = $qt
If Not FileExists($pdffile) Then
If $cli = 0 Then
MsgBox(0, $msgTitle, $pdffile & " - File not found.", 10)
EndIf
Exit
EndIf
If $pdffile <> "" Then
Local $custom = 0
If FileExists(@ScriptDir & "\PDF-Xchange Viewer Settings.dat") Then $custom = 1
Local $myDir = @TempDir & "\PDFPrinterTmp"
DirCreate($myDir)
FileInstall("d:\Dropbox\vdosinst\programs\PDFXCview.exe", $myDir & "\PDFXCview.exe")
FileInstall("d:\Dropbox\vdosinst\programs\resource.dat", $myDir & "\resource.dat", 1)
FileDelete($myDir & "\settings.dat")
If $custom = 1 Then
FileCopy(@ScriptDir & "\PDF-Xchange Viewer Settings.dat", $myDir & "\settings.dat", 1)
Else
FileInstall("d:\Dropbox\vdosinst\programs\settings.dat", $myDir & "\settings.dat", 1)
EndIf
If $specified = 1 Then
; $printstring = " /print:printer=" & $qt & $printername & $qt & $pgvar ; fixed per Peter Mickle
$printstring = " " & $qt & "/printto:" & $pgvar & $qt & $printername & $qt
For $i = 1 To $copies
If Not @Compiled Then ConsoleWrite("specified: " & @LF & $qt & $myDir & "\PDFXCview.exe" & $qt & $printstring & _
" " & $qt & $pdffile & $qt & @LF)
RunWait($qt & $myDir & "\PDFXCview.exe" & $qt & " /importp settings.dat", $myDir, @SW_SHOW)
RunWait($qt & $myDir & "\PDFXCview.exe" & $qt & $printstring & _
" " & $qt & $pdffile & $qt, $myDir, @SW_SHOW)
If @error Then
If $cli = 0 Then
MsgBox(0, $msgTitle, @error & @CRLF & @CRLF & "Could not run PDFXCview.EXE.")
EndIf
ExitLoop
EndIf
$basestring = StringLeft($pdffile, StringLen($pdffile) - 3)
Next
Else
If $showselptr = 1 Then
Local $ptrselmsg = "Select a printer for this document:"
$printername = 0
GetPrinter($ptrselmsg)
Do
Sleep(100)
Until $printername
$noprinter = 0
If $printername = "nul" Then
$noprinter = 1
EndIf
$printstring = " /printto:" & $pgvar & $qt & $printername & $qt ; fixed per Peter Mickle
Else
$printstring = " " & $qt & "/print:default=no" & $pgvar ; & $qt
EndIf
If $noprinter = 0 Then
For $i = 1 To $copies
RunWait($qt & $myDir & "\PDFXCview.exe" & $qt & " /importp settings.dat", $myDir, @SW_SHOW)
RunWait($qt & $myDir & "\PDFXCview.exe" & $qt & $printstring & " " & _
$qt & $pdffile & $qt, $myDir, @SW_SHOW)
If @error Then
If $cli = 0 Then
MsgBox(0, $msgTitle, @error & @CRLF & @CRLF & "Could not run PDFXCview.EXE.")
EndIf
ExitLoop
EndIf
Next
EndIf
$basestring = StringLeft($pdffile, StringLen($pdffile) - 3)
EndIf
If $debug = 1 Then
ClipPut($qt & $myDir & "\PDFXCview.exe" & $qt & $printstring & _
" " & $qt & $pdffile & $qt)
If $cli = 0 Then
MsgBox(0, $msgTitle, "The PDFXCview.exe print command has been copied to the clipboard. " & _
"In case of problems, open a command windows, and paste it in and experiment with it.")
EndIf
EndIf
EndIf
If $focus <> "" Then WinActivate($focus)
Exit
;Func GetDefaultPrinter()
; $currentprinter = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\", "Device")
; $defaultprinter = StringLeft($currentprinter, StringInStr($currentprinter, ",") - 1)
; If $defaultprinter = "" Then $defaultprinter = 0
;EndFunc ;==>GetDefaultPrinter
Func GetPrinter($ptrselmsg)
Global $printer_list[1]
Global $printer_list_ext[1]
Global $printer_radio_array[1]
$regprinters = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices"
$currentprinter = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\", "Device")
$defaultprinter = StringLeft($currentprinter, StringInStr($currentprinter, ",") - 1)
Dim $i = 1
Dim $erreur_reg = False
While Not $erreur_reg
$imprimante = RegEnumVal($regprinters, $i)
$erreur_reg = @error
If Not $erreur_reg Then
_ArrayAdd($printer_list, $imprimante)
_ArrayAdd($printer_list_ext, $imprimante & "," & RegRead($regprinters, $imprimante))
EndIf
$i = $i + 1
WEnd
_ArrayDelete($printer_list, 0)
_ArrayDelete($printer_list_ext, 0)
If UBound($printer_list) >= 2 Then ;; if 2 or more printers available, we show the dialog
Dim $groupheight = (UBound($printer_list) + 1) * 25 ;; 30
Dim $guiheight = $groupheight + 50
Dim $buttontop = $groupheight + 20
Opt("GUIOnEventMode", 1)
$gh = GUICreate($ptrselmsg, 400, $guiheight)
Dim $font = "Verdana"
GUISetFont(10, 400, 0, $font)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetFont(10, 400, 0, $font)
GUICtrlCreateGroup("Available printers:", 10, 10, 380, $groupheight)
Dim $position_vertical = 5 ;; 0
For $i = 0 To UBound($printer_list) - 1 Step 1
GUISetFont(10, 400, 0, $font)
$position_vertical = $position_vertical + 25 ;; 30
$radio = GUICtrlCreateRadio($printer_list[$i], 20, $position_vertical, 350, 20)
_ArrayAdd($printer_radio_array, $radio)
If $currentprinter = $printer_list_ext[$i] Then
GUICtrlSetState($radio, $GUI_CHECKED)
EndIf
Next
_ArrayDelete($printer_radio_array, 0)
GUISetFont(10, 400, 0, $font)
$okbutton = GUICtrlCreateButton("OK", 10, $buttontop, 50, 25)
GUICtrlSetOnEvent($okbutton, "OKButton")
Local $AccelKeys[2][2] = [["{ENTER}", $okbutton], ["^O", $okbutton]]
GUISetAccelerators($AccelKeys)
GUISetState()
EndIf
EndFunc ;==>GetPrinter
Func OKButton()
For $i = 0 To UBound($printer_radio_array) - 1 Step 1
If GUICtrlRead($printer_radio_array[$i]) = 1 Then
$printername = StringLeft($printer_list_ext[$i], StringInStr($printer_list_ext[$i], ",") - 1)
EndIf
Next
GUIDelete($gh)
If Not @Compiled Then ConsoleWrite($printername & @LF)
EndFunc ;==>OKButton
Func CLOSEClicked()
GUIDelete($gh)
$printername = "nul"
If Not @Compiled Then ConsoleWrite($printername & @LF)
EndFunc ;==>CLOSEClicked
;~ Func Cancelled()
;~ If $cli = 0 Then
;~ MsgBox(262144, $msgTitle, "Script cancelled.")
;~ EndIf
;~ Exit
;~ EndFunc ;==>Cancelled
Func _FileIsUsed($sFilePath) ;; By Nessie. Modified by guinness.
Local Const $hFileOpen = _WinAPI_CreateFile($sFilePath, $CREATE_ALWAYS, (DriveGetType($sFilePath)) = 'NETWORK' ? $FILE_SHARE_READ : $FILE_SHARE_WRITE)
Local $fReturn = True
If $hFileOpen Then
_WinAPI_CloseHandle($hFileOpen)
$fReturn = False
EndIf
If $fReturn Then
$fReturn = _WinAPI_GetLastError() = $ERROR_SHARING_VIOLATION
EndIf
Return $fReturn
EndFunc ;==>_FileIsUsed
暂无答案!
目前还没有任何答案,快来回答吧!