bbbngowc Posted October 16, 2009 Share Posted October 16, 2009 Hi,Prolly been asked like a zillion times but, is there a way to print pdf files from command line? I tried the AcroRD32.exe /t but the application just opens, prints the doc and stays open. Not until I close the application would it open the other and print. Using Adobe Reader 9.0. Anyone has something to work for this?Thanks. Link to comment Share on other sites More sharing options...
bbbngowc Posted October 20, 2009 Author Share Posted October 20, 2009 Found this online. Thank to the coder for providing it. It works for what I need.@ECHO OFF:: Check Windows version, abort if not NT 4 or laterIF NOT "%OS%"=="Windows_NT" GOTO SyntaxSETLOCAL ENABLEDELAYEDEXPANSION:: Initialize variablesSET PrintCmd=SET Temp=%Temp:"=%SET NumFiles=0SET MultiPrint=0SET ListTool=:: Check command line argumentsIF "%~1"=="" GOTO SyntaxIF NOT "%~3"=="" GOTO SyntaxIF "%~2"=="" ( SET FileSpec=%~1) ELSE ( IF /I "%~1"=="/M" SET FileSpec=%~2 IF /I "%~2"=="/M" SET FileSpec=%~1)ECHO.%* | FIND /I "/M" >NUL && SET MultiPrint=1ECHO.%FileSpec% | FIND "/" >NUL && GOTO SyntaxIF NOT EXIST "%FileSpec%" GOTO Syntax:: Count the number of files specified by filespecFOR %%A IN (%FileSpec%) DO SET /A NumFiles = !NumFiles! + 1IF %NumFiles% EQU 0 GOTO Syntax:: Check if we need to have access to a list of processes:: currently running, and if so, which one is availableIF %NumFiles% GTR 1 SET MultiPrint=1IF %MultiPrint% EQU 0 CALL :GetListTool:: Get the file association from the registryFOR /F "tokens=1* delims==" %%A IN ('ASSOC .PDF') DO ( FOR /F "tokens=1 delims==" %%C IN ('FTYPE ^| FIND /I "%%~B"') DO ( CALL :GetPrintCommand %%C )):: Check if a print command was foundIF NOT DEFINED PrintCmd ( ECHO. ECHO No print command seems to be assiociated with .PDF files on this computer. GOTO Syntax):: Print the file using the print command we just foundFOR %%A IN (%FileSpec%) DO CALL :ExecPrintCommand "%%~fA":: A final messageIF "%MultiPrint%"=="1" ( ECHO. ECHO You will need to close the Acrobat Reader window manually after the printing ECHO is finished. IF "%NumFiles%"=="1" IF "%ListTool%"=="" ( rem ECHO rem ECHO rem ECHO )):: DoneGOTO End:ExecPrintCommandCALL START /MIN "PrintPDF" %PrintCmd%GOTO:EOF:GetListTool:: Now we need to find a tool to check for processes.:: In XP and later this will be the native TASKLIST command,:: in NT 4 and 2000 we'll need to find a non-native tool.:: First we'll try TASKLIST ...TASKLIST >NUL 2>&1IF ERRORLEVEL 1 ( REM ... if TASKLIST isn't available we'll try TLIST next ... TLIST >NUL 2>&1 IF ERRORLEVEL 1 ( REM ... and if that isn't available either we'll try PSLIST ... PSLIST >NUL 2>&1 IF NOT ERRORLEVEL 1 SET ListTool=PSLIST ) ELSE ( SET ListTool=TLIST )) ELSE ( SET ListTool=TASKLIST):: Don't worry if we didn't find ANY tool to list processes, in:: that case we'll just assume multiple PDFs need to be printedIF "%ListTool%"=="" SET MultiPrint=1GOTO:EOF:GetPrintCommand:: Get the print command for this file type from the registrySTART /WAIT REGEDIT.EXE /E "%Temp%.\pdf.dat" "HKEY_CLASSES_ROOT\%1\shell\print\command"IF NOT EXIST "%Temp%.\pdf.dat" GOTO:EOFFOR /F "tokens=1* delims==" %%D IN ('TYPE "%TEMP%.\pdf.dat" ^| FIND "@="') DO SET PrintCmd=%%EDEL "%Temp%.\pdf.dat"SET PrintCmd=%PrintCmd:\"="%SET PrintCmd=%PrintCmd:""="%SET PrintCmd=%PrintCmd:\\=\%:: The /T switch terminates Acrobat Reader after printing.:: Thanks to Fabio Quieti for sending me this tip.:: However, as Michael Butler pointed out, it should not be:: used when printing lots of files.:: So I introduced a /M switch for this batch file, stating:: that multiple files are to be printed.:: Without specifying the /M switch, this will also be true:: when wildcards are used in the filespec.:: Finally, if another Adobe Reader process is running right:: now, we won't be using the /T switch either.IF %MultiPrint% EQU 0 CALL :CheckProcess %PrintCmd%IF %MultiPrint% EQU 0 ( SET PrintCmd=%PrintCmd:"%1"=/t "%%%~1"% rem SET PrintCmd=%PrintCmd% /t "%%~1") ELSE ( SET PrintCmd=%PrintCmd:"%1"="%%%~1"% rem SET PrintCmd=%PrintCmd% "%%~1")GOTO:EOF:CheckProcessIF "%ListTool%"=="" ( SET MultiPrint=1) ELSE ( %ListTool% 2>&1 | FIND /I "%~n1" >NUL && SET MultiPrint=1)GOTO:EOF:SyntaxECHO.ECHO PrintPDF.bat, Version 3.11 for Windows NT 4 / 2000 / XP / Server 2003ECHO Prints PDF files from the command lineECHO.ECHO Usage: PRINTPDF pdf_filespec [ /M ]ECHO.ECHO Where: "pdf_filespec" is the file name or filespec of the PDF file(s)ECHO to be printed; wildcards allowed (*); use doubleECHO quotes for long file namesECHO.rem ECHO Notes: This batch file has been tested with Acrobat Reader versions 5-7 only.rem ECHO It requires Adobe/Acrobat Reader, and will NOT work if Acrobat "Writer"rem ECHO is installed.rem ECHO Thanks to Fabio Quieti, as of version 3.00, you no longer need to closerem ECHO the minimized Acrobat Reader window manually, after printing the file.rem ECHO Thanks to Michael Butler, printing lots of PDFs will no longer make therem ECHO computer slow down to a crawl or even hang.rem ECHO.rem ECHO Written by Rob van der Wouderem ECHO http://www.robvanderwoude.com:EndIF "%OS%"=="Windows_NT" ENDLOCAL Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now