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.

1
  • Linux, sorry, I forgot! I'll edit now
    – PolGZ
    May 29 at 15:50

2 Answers 2

1

You can use a for loop like this:

for file in *.pdf; do pdftk "$file" stamp watermark.pdf output "WM-$file"; done
2
  • 1
    -.-' That was not complicated... I've been trying for more than half an hour... xD. I thought that would apply the command to the files themselves, but that I would need to do something different to get the filename for the output... and I was getting "Input errors, so no output", so I thought I was already failing at searching the files... Anyway, Thank you very much! Clearly I'm not good understanding computing logic!
    – PolGZ
    May 29 at 16:05
  • Recommended reading; "Bash guides" at www.tldp.org - slightly old but still a jumpstart for anyone.
    – Hannu
    May 29 at 16:19
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .