1

I've learned here to apply a watermark to a pdf file without opening it by doing:

pdftk input.pdf stamp watermark.pdf output output.pdf

Now I wanted to do this to every .pdf on a given directory, either substituting the original .pdfs or creating newer ones with the same names + something like -WM.pdf

But this command requires an input file name and output file name, so I don't know how to do a for loop for it.

On Linux.

PolGZ
  • 23

3 Answers3

1

You can use a for loop like this:

for file in *.pdf; do pdftk "$file" stamp watermark.pdf output "WM-$file"; done
Yisroel Tech
  • 13,220
0

For Windows users a similar result would be at console

for %f in (*.pdf) do pdftk "%f" stamp watermark.pdf output "%~dpnf-wm.pdf"

or in a script

for %%f in (*.pdf) do pdftk "%%f" stamp watermark.pdf output "%%~dpnf-wm.pdf"
pause

if there are problems you should watch for feedback by use pause such as

Error: Failed to open PDF file:
   create-forms-sample.pdf
   OWNER PASSWORD REQUIRED, but not given (or incorrect)
Errors encountered.  No output created.
Done.  Input errors, so no output created.

Likewise PDFtk can lock up on some files, but that is rarer

Error: Failed to open PDF file: f1040-fred

K J
  • 1,248
-2

To apply a watermark to every PDF in directory, the user can switch to a skilled tool that can easily and quickly apply a watermark to the PDFs.Users can use the Pcinfotools PDF Watermark Tool because it can watermark PDF files and maintain their integrity while watermarking them.