0

I want to create a script which uses pdftk to add a watermark stamp to pdf files. After the stamp is applied the output file doesn't need to be renamed

My problem is I don't know what the file name will be called, and pdftk requires a different file name for the input and output files.

The syntax for pdftk is simple enough:

pdftk inputfile.pdf stamp watermark.pdf output outputfile.pdf

I feel like this should be a trivial thing to do using vbs but I'm scratching my head. Help greatly appreciated.

1 Answers1

0

I figured it out - using the file system object to process the entire folder one file at a time with a different out put folder:

'create the file system object and the windows shell object
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

'process all the files in the input folder
Set objFolder = objFSO.GetFolder(strInputPath)
Set colFiles = objFolder.Files

For Each objFile in colFiles

 strInputFilePath =  chr(34) & objFile.Path & chr(34)
 strOutputFilePath = chr(34) & strOutputPath & objFile.Name & chr(34)

'build the command
 strCommand = "pdftk " & strInputFilePath & " stamp " & strLetterheadFilePath & " output " & strOutputFilePath

' execute the command
 WshShell.Run strCommand
' delete the input file
 objFSO.DeleteFile(objFile.Path)
Next