@echo off :: test for command extensions set no_extensions=false VERIFY OTHER 2>nul SETLOCAL ENABLEEXTENSIONS IF ERRORLEVEL 1 goto no_cmd_extensions :start_here ::---------------------------------------------------------------------------------------------------------- ::---------------------------------------------------------------------------------------------------------- ::------------------------------------Your edits are below here ------------------------------------- ::---------------------------------------------------------------------------------------------------------- ::---------------------------------------------------------------------------------------------------------- :: IMPORTANT NOTE REGARDING ALL PATHS: :: DON'T FORGET TO... :: - prefix all paths with a drive letter :: - enclose path in quotes if path includes spaces :: - end with backslash :: (e.g. "C:\My Utilities\") :: set to location of ps2pdf.bat - on a fresh install, typically in the ...\gs\gsX.X\lib folder set GHOST_SCRIPT_PS2PDF_FOLDER="C:\Program Files\gs\gs8.51\lib\" :: set to location of gswin32c.exe - on a fresh install, typically in the ...\gs\gsX.X\bin folder set GHOST_SCRIPT_BINARY_FOLDER="C:\Program Files\gs\gs8.51\bin\" :: set to location of SED.exe set SED_PATH="C:\Program Files\gs\gs8.51\bin\" :: set to any folder where you have read/write/execute permission set WRITEABLE_FOLDER=C:\ :: Printfile is our print command -- you likely won't need to use it. :: change from my sample if using, else comment out with REM or :: set PrintFile_Folder="C:\Program Files\gs\gs8.51\bin\" :: only set PDF_DESTINATION_FOLDER if you want your PDF dumped in a particular folder :: other than WRITEABLE_FOLDER :: you may comment out the following line by prepending a REM or a :: to the front of it set PDF_DESTINATION_FOLDER="C:\Documents and Settings\%username%\Desktop\PDF_files\" :: ANOTHER IMPORTANT NOTE - IF YOUR CHANGE ANY OF THE FOUR SETTINGS BELOW, :: THEN BE SURE TO DELETE YOUR WATERMARK.SED FILE SO THAT THEY'LL TAKE EFFECT. :: This batch file will automatically create the necessary SED script file if one is not already present. :: If watermark.sed *is* present, then this routine won't overwrite it. :: change YOUR_CUSTOM_WATERMARK to read as you like it. Each line of text must be enclosed in a pair of parenthese. set YOUR_CUSTOM_WATERMARK=(DRAFT/REVIEW) (YOUR CUSTOMIZED) (WATERMARK HERE) :: change YOUR_GLOBAL_SCALE_FACTOR to scale all of the watermark lettering set YOUR_GLOBAL_SCALE_FACTOR=4 :: change YOUR_INTERLINEAR_SPACING to adjust the spacing between lines of watermark text set YOUR_INTERLINEAR_SPACING=0.5 :: change YOUR_WATERMARK_INTENSITY to adjust the intensity of the watermark, from 0.0 (= full black) to 1.0 (= full white) set YOUR_WATERMARK_INTENSITY=0.95 ::---------------------------------------------------------------------------------------------------------- ::---------------------------------------------------------------------------------------------------------- ::--------That's it... you enter the first 10 lines worth of SET commands. I'll do the rest... ------ ::-------- Don't edit below unless you know what you are doing!! (At least keep a backup.) ----- ::---------------------------------------------------------------------------------------------------------- ::---------------------------------------------------------------------------------------------------------- set path=%path%;%GHOST_SCRIPT_BINARY_FOLDER%;%GHOST_SCRIPT_PS2PDF_FOLDER%;%SED_PATH%;%PrintFile_Folder% set plotfile=%1 echo Processing %plotfile% echo. if not exist %plotfile% goto no_plotfile FOR %%A IN (%1) DO set file_base_name=%%~nA FOR %%A IN (%1) DO set file_extension_test=%%~xA if "%file_extension_test%" == ".ps" goto check_for_watermark_script if "%file_extension_test%" == ".plt" goto check_for_watermark_script goto unsupported_extension :check_for_watermark_script if not exist %WRITEABLE_FOLDER% md %WRITEABLE_FOLDER% if not exist %WRITEABLE_FOLDER%watermark.sed goto create_script :script_created if not exist %WRITEABLE_FOLDER%watermark.sed goto script_create_error %SED_PATH%sed -n -f %WRITEABLE_FOLDER%watermark.sed %plotfile% >%WRITEABLE_FOLDER%%file_base_name%.wmk if not exist %WRITEABLE_FOLDER%%file_base_name%.wmk goto watermark_create_error ::check also for file size of zero FOR %%A IN (%WRITEABLE_FOLDER%%file_base_name%.wmk) DO set wmk_size_test=%%~zA if "%wmk_size_test%" == "0" goto watermark_create_error del %plotfile% if exist %WRITEABLE_FOLDER%%file_base_name%.ps del %WRITEABLE_FOLDER%%file_base_name%.ps ren %WRITEABLE_FOLDER%%file_base_name%.wmk %file_base_name%.ps :get_user_choice ::-------------------------------%<-------Dialog box method: If JScript is disabled, method below will automatically be used. ------------------------ if "%no_extensions%"==true goto screen1 :popup1 >c:\watermark.js echo return_code = PopupBox("Press:\nYes -\tto print\nNo -\tto PDF\nCancel -\tto Quit", "Print / PDF / Cancel?", 3, 32); >>c:\watermark.js echo WScript.Quit(return_code); >>c:\watermark.js echo //=========================================================== >>c:\watermark.js echo // function PopupBox shows popup button dialog >>c:\watermark.js echo // called with string msg, string title, integer buttons, integer IconType >>c:\watermark.js echo // button values: 0 = OK; 1 = OK/Cancel; 2 = Abort/Retry/Ignore; 3 = Yes/No/Cancel; 4 = Yes/No; 5 = Retry/Cancel; >>c:\watermark.js echo // IconType values: 0 = none; 16 = Stop mark; 32 = Question mark; 48 = Exclamation mark; 64 = Information icon >>c:\watermark.js echo // returns 1 = OK; 2 = Cancel; 3 = Abort; 4 = Retry; 5 = Ignore; 6 = Yes; 7 = No >>c:\watermark.js echo //=========================================================== >>c:\watermark.js echo function PopupBox(msg, title, ShownButtons, IconType) { >>c:\watermark.js echo var WshShell = WScript.CreateObject("WScript.Shell"); >>c:\watermark.js echo var BtnCode = WshShell.Popup(msg, 0, title, ShownButtons + IconType); >>c:\watermark.js echo return BtnCode; >>c:\watermark.js echo } if not exist c:\watermark.js goto no_popup c:\watermark.js if errorlevel 7 goto user_pressed_no if errorlevel 6 goto user_pressed_yes if errorlevel 2 goto user_pressed_cancel :screen1 >c:\geta_key.scr echo A 100 >>c:\geta_key.scr echo MOV AH,08 >>c:\geta_key.scr echo INT 21 >>c:\geta_key.scr echo CMP AL,0 >>c:\geta_key.scr echo JNZ 010A >>c:\geta_key.scr echo INT 21 >>c:\geta_key.scr echo MOV AH,4C >>c:\geta_key.scr echo INT 21 >>c:\geta_key.scr echo. >>c:\geta_key.scr echo RCX >>c:\geta_key.scr echo E >>c:\geta_key.scr echo N c:\geta_key.com >>c:\geta_key.scr echo W >>c:\geta_key.scr echo Q debug< c:\geta_key.scr cls :get_da_input echo (P)rint, (M)ake PDF, (C)ancel? c:\geta_key If errorlevel 112 if not errorlevel 113 goto do_print If errorlevel 109 if not errorlevel 110 goto do_pdf If errorlevel 99 if not errorlevel 100 goto user_pressed_cancel If errorlevel 80 if not errorlevel 81 goto do_print If errorlevel 77 if not errorlevel 78 goto do_pdf If errorlevel 67 if not errorlevel 68 goto user_pressed_cancel echo Choose a letter: P, M, or C. goto get_da_input :user_pressed_cancel echo User cancelled. goto end_it :user_pressed_yes goto do_print :user_pressed_no goto do_pdf ::-------------------------------%<-------Dialog box method: If JScript is disabled, you'll have to use the method above to get user input. ------------------------ :do_print ::Put your print command here instead of mine echo This is line 158 of the batch file watermark.bat. echo Replace my print command -- which follows -- with your own. echo %GHOST_SCRIPT_BINARY_FOLDER%prfile32.exe "/n:Default settings" /q %WRITEABLE_FOLDER%%file_base_name%.ps pause goto end_it :do_pdf if not exist %ghost_script_ps2pdf_folder%ps2pdf.bat goto gs_ps2pdf_not_set_error if not exist %GHOST_SCRIPT_BINARY_FOLDER%gswin32.exe goto gs_bin_not_set_error if exist %WRITEABLE_FOLDER%%file_base_name%.pdf del %WRITEABLE_FOLDER%%file_base_name%.pdf call ps2pdf %WRITEABLE_FOLDER%%file_base_name%.ps %WRITEABLE_FOLDER%%file_base_name%.pdf if %PDF_DESTINATION_FOLDER%/ == / goto no_pdf_drop_location goto move_to_pdf_drop_folder :no_pdf_drop_location set pdf_dest_folder=%WRITEABLE_FOLDER% goto report_location :move_to_pdf_drop_folder set pdf_dest_folder=%PDF_DESTINATION_FOLDER% if not exist %pdf_dest_folder% md %pdf_dest_folder% move /Y %WRITEABLE_FOLDER%%file_base_name%.pdf %PDF_DESTINATION_FOLDER% goto report_location :report_location FOR %%A IN (%pdf_dest_folder%%file_base_name%.pdf) DO set pdf_location=%%~dpA echo PDF file located in %pdf_location% pause goto end_it :create_script >%WRITEABLE_FOLDER%watermark.sed echo p >>%WRITEABLE_FOLDER%watermark.sed echo /^%%^%%EndPageSetup/ a\ >>%WRITEABLE_FOLDER%watermark.sed echo /theWatermark {[%YOUR_CUSTOM_WATERMARK%]} def\ >>%WRITEABLE_FOLDER%watermark.sed echo /globalScaleFactor {%YOUR_GLOBAL_SCALE_FACTOR%} def\ >>%WRITEABLE_FOLDER%watermark.sed echo /grayScale {%YOUR_WATERMARK_INTENSITY%} def\ >>%WRITEABLE_FOLDER%watermark.sed echo /interLinearSpacing {%YOUR_INTERLINEAR_SPACING%} def\ >>%WRITEABLE_FOLDER%watermark.sed echo /getmidpage {currentpagedevice /PageSize get dup 0 get exch 1 get exch 2 div exch 2 div} bind def\ >>%WRITEABLE_FOLDER%watermark.sed echo /corner2corner {currentpagedevice /PageSize get dup 0 get exch 1 get exch atan} bind def\ >>%WRITEABLE_FOLDER%watermark.sed echo /getsheetscal {currentpagedevice /PageSize get 0 get 72 div globalScaleFactor mul} bind def\ >>%WRITEABLE_FOLDER%watermark.sed echo /sizefont {/Helvetica-Bold findfont exch scalefont setfont} bind def\ >>%WRITEABLE_FOLDER%watermark.sed echo /showcenterjust {dup stringwidth pop 2 div neg 0 rmoveto show} bind def\ >>%WRITEABLE_FOLDER%watermark.sed echo /numwatermarklines {theWatermark length} bind def\ >>%WRITEABLE_FOLDER%watermark.sed echo /watermark {gsave newpath getmidpage moveto corner2corner rotate 0 getsheetscal 2 div neg rmoveto\ >>%WRITEABLE_FOLDER%watermark.sed echo 0 numwatermarklines 1 sub getsheetscal mul interLinearSpacing mul rmoveto getsheetscal sizefont\ >>%WRITEABLE_FOLDER%watermark.sed echo grayScale setgray theWatermark {gsave showcenterjust grestore 0 2 getsheetscal mul interLinearSpacing mul\ >>%WRITEABLE_FOLDER%watermark.sed echo neg rmoveto} forall\ >>%WRITEABLE_FOLDER%watermark.sed echo grestore} bind def\ >>%WRITEABLE_FOLDER%watermark.sed echo ^<^<\ >>%WRITEABLE_FOLDER%watermark.sed echo /BeginPage {watermark} bind\ >>%WRITEABLE_FOLDER%watermark.sed echo ^>^> setpagedevice\ goto script_created ::====================caught errors below=================== :unsupported_extension if "%no_extensions%"==true goto screen2 :popup2 >c:\watermark.js echo var msg = "Unsupported file extension (.ps or .plt ONLY)"; >>c:\watermark.js echo WScript.Echo(msg); c:\watermark.js goto end_it :screen2 echo Unsupported file extension (.ps or .plt ONLY) pause goto end_it :no_plotfile :: can't find plot file: bad file type? bad mapkey? no plot file set as %1? if "%no_extensions%"==true goto screen3 :popup3 >c:\watermark.js echo var msg = "Can\'t find plot file. Check:\n"; >>c:\watermark.js echo msg += " - plot file set?\n"; >>c:\watermark.js echo msg += " - correct file type? (PostScript only)\n"; >>c:\watermark.js echo msg += " - bad mapkey?"; >>c:\watermark.js echo WScript.Echo(msg); c:\watermark.js goto end_it :screen3 echo Can't find plot file. Check: echo - plot file set? echo - correct file type? (PostScript only) echo - bad mapkey? pause goto end_it :script_create_error ::Can't find watermark.sed: no write access?? if "%no_extensions%"==true goto screen4 :popup4 >c:\watermark.js echo var msg = "Can\'t find watermark script file. Check:\n"; >>c:\watermark.js echo msg += " - no write access to specified WRITEABLE_FOLDER?\n"; >>c:\watermark.js echo WScript.Echo(msg); c:\watermark.js goto end_it :screen4 echo Can't find watermark script file. Check: echo - no write access to specified WRITEABLE_FOLDER? pause goto end_it :watermark_file_absent ::Can't find watermarked file: no write access to WRITEABLE_FOLDER? SED command not in path? SED_FOLDER not set? if "%no_extensions%"==true goto screen5 :popup5 >c:\watermark.js echo var msg = "Can\'t find watermarked file. Check:\n"; >>c:\watermark.js echo msg += " - no write access to specified WRITEABLE_FOLDER?\n"; >>c:\watermark.js echo WScript.Echo(msg); c:\watermark.js goto end_it :screen5 echo Can't find watermarked file. Check: echo - no write access to specified WRITEABLE_FOLDER? pause goto end_it :watermark_create_error ::Can't find watermarked file: no write access to WRITEABLE_FOLDER? SED command not in path? SED_FOLDER not set? if "%no_extensions%"==true goto screen6 :popup6 >c:\watermark.js echo var msg = "Watermark file output truncated. Check:\n"; >>c:\watermark.js echo msg += " - SED.exe command not in OS path?\n"; >>c:\watermark.js echo msg += " - SED_FOLDER not set?\n"; >>c:\watermark.js echo WScript.Echo(msg); c:\watermark.js goto end_it :screen6 echo Watermark file output truncated. Check: echo - SED.exe command not in OS path? echo - SED_FOLDER not set? pause goto end_it :gs_ps2pdf_not_set_error ::Can't find file ps2pdf.bat: GHOST_SCRIPT_PS2PDF_FOLDER not set in batch file? if "%no_extensions%"==true goto screen7 :popup7 >c:\watermark.js echo var msg = "Can't find file ps2pdf.bat for PDF conversion. Check:\n"; >>c:\watermark.js echo msg += " - GHOST_SCRIPT_PS2PDF_FOLDER not set in print_or_pdf.bat?\n"; >>c:\watermark.js echo msg += " - GHOST_SCRIPT_PS2PDF_FOLDER set CORRECTLY?\n"; >>c:\watermark.js echo WScript.Echo(msg); c:\watermark.js goto end_it :screen7 echo Can't find file ps2pdf.bat for PDF conversion. Check: echo - GHOST_SCRIPT_PS2PDF_FOLDER not set in print_or_pdf.bat? echo - GHOST_SCRIPT_PS2PDF_FOLDER set CORRECTLY? pause goto end_it :gs_bin_not_set_error ::Can't find file gswin32c.exe: GHOST_SCRIPT_BIN_FOLDER not set in batch file? if "%no_extensions%"==true goto screen8 :popup8 >c:\watermark.js echo var msg = "Can't find file gswin32c.exe for PDF conversion. Check:\n"; >>c:\watermark.js echo msg += " - GHOST_SCRIPT_BIN_FOLDER set CORRECTLY?\n"; >>c:\watermark.js echo WScript.Echo(msg); c:\watermark.js goto end_it :screen8 echo Can't find file gswin32c.exe for PDF conversion. Check: echo - GHOST_SCRIPT_BIN_FOLDER set CORRECTLY? pause goto end_it :no_popup ::Can't create popup dialog box: no write access to WRITEABLE_FOLDER? JScript disallowed on system? No WSH? cls echo Can't create popup dialog box. Check: echo - no write access to specified WRITEABLE_FOLDER? echo - JScript (*.js) disallowed on system? echo - Windows Scripting Host (WSH) not installed? echo. echo. pause goto end_it :no_cmd_extensions set no_extensions=true echo. echo Unable to enable command extensions. echo No dialog boxes will be used. echo. goto start_here :end_it if exist c:\watermark.js del c:\watermark.js if exist %WRITEABLE_FOLDER%%file_base_name%.wmk del %WRITEABLE_FOLDER%%file_base_name%.wmk if exist %WRITEABLE_FOLDER%%file_base_name%.ps del %WRITEABLE_FOLDER%%file_base_name%.ps if exist c:\geta_key.scr del c:\geta_key.scr if exist c:\geta_key.com del c:\geta_key.com