其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
Windows下打印PDF的Script

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

为了能够使用户在下载系统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:[email protected]
:End
ENDLOCAL




相关文章

相关软件