Windows下打印PDF的Script

王朝system·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

为了能够使用户在下载系统Server生成的PDF文件后,自动打印。有一些第三方软件是可以直接打印PDF,但都需要购买。所以,写了下面一段Script,并且主要解决与客户端AcrobatReader的安装目录无关。

@ECHO OFF

ECHO Usage: PRINTPDF pdf_file

ECHO.

ECHO Where: "pdf_file" is the name of the PDF file to be printed.

ECHO.

ECHO Notes: This batch file works only if PDF files' default association is any

ECHO Acrobat Reader version.

ECHO Modification of the code to check for valid association by Chuck Hicks.

ECHO Modification of the code to enable long file names by Michael Lintner.

SETLOCAL

:: Command line parsing

IF [%1]==[] GOTO Syntax

SET File2Print=%~1

ECHO.%File2Print% | FIND "?" >NUL

IF NOT ERRORLEVEL 1 GOTO Syntax

IF NOT EXIST "%File2Print%" GOTO Syntax

:: Strip quotes from TEMP variable

SET TEMP=%TEMP:"=%

:: Get the file association from the registry

START /WAIT REGEDIT.EXE /E "%TEMP%.\pdf.dat" "HKEY_CLASSES_ROOT\.pdf"

FOR /F "tokens=1* delims==" %%A IN ('TYPE "%TEMP%.\pdf.dat" ^| FIND "@="') DO SET FileType=%%B

SET Filetype=%FileType:"=%

:: Get the print command for this file type from the registry

START /WAIT REGEDIT.EXE /E "%TEMP%.\pdf.dat" "HKEY_CLASSES_ROOT\%FileType%\shell\print\command"

SET PrintCmd=

:: Check for valid association by blocking "{"; modification by Chuck Hicks.

FOR /F "tokens=1* delims==" %%A IN ('TYPE "%TEMP%.\pdf.dat" ^| FIND /V "{" ^| FIND "@="') DO SET PrintCmd=%%B

:: If no default was found, then Acrobat Writer may be installed

IF NOT DEFINED PrintCmd GOTO AcroWriter

SET PrintCmd=%PrintCmd:\"="%

SET PrintCmd=%PrintCmd:""="%

SET PrintCmd=%PrintCmd:\\=\%

:: Next line enables long file names, added by Michael Lintner

SET PrintCmd=%PrintCmd:"%1"=%%1%

:: Actual print command has to be stored in a temporary batch file,

:: which is used as the batch language's "eval" substitute

> "%TEMP%.\~PrnPdf.bat" ECHO START "Print" %PrintCmd%

CALL "%TEMP%.\~PrnPdf.bat" %File2Print%

:: Cleanup

DEL "%TEMP%.\pdf.dat"

DEL "%TEMP%.\~PrnPdf.bat"

:: Done

GOTO End

:AcroWriter

ECHO. Not finished

GOTO End

:Syntax

ECHO.

ECHO.

ECHO Written by Andy Chen

ECHO mailto:andy.chen.sh@gmail.com

:End

ENDLOCAL

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航