Page 1 of 1

stamp a watermark with pdftk

Posted: 28 Feb 2011 16:15
by calude
Hi
I need some help for a big batch operation on 1300 separate pdfs

the project is to stamp a watermark on each of the selected pdf files, then save it with the same name with a postfix in a sub-folder.
for this I want to use PDF-Tool Kit (pdftk) http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
the user manual is here http://www.pdflabs.com/docs/pdftk-man-page/
and examples here:http://www.pdflabs.com/docs/pdftk-cli-examples/

the command line syntax for this is:

Code: Select all

pdftk orig.pdf stamp watermark.pdf output result.pdf
I have already some UDC that works in the OPEN category the following works as expected but only on one file at a time

Code: Select all

"C:\Windows\System32\pdftk.exe" <curitem> stamp "D:\CV_mes_documents\wm\WM1.pdf" output "D:\CV_mes_documents\wm\WM_output\<curbase>_wm.<curext>"
as a script the same code works too

Code: Select all

 open "C:\Windows\System32\pdftk.exe" <curitem> stamp "D:\CV_mes_documents\wm\WM1.pdf" output "D:\CV_mes_documents\wm\WM_output\<curbase>_wm.<curext>"
I tried to transform my working code to udc "openwith" which allows multiple instances but with my limited understanding of all this and the syntax being a little different I'm looking for a hand.
either a "openwith" codeline or a script that could talk to pdftk

thanks a lot

Claude

Re: stamp a watermark with pdftk

Posted: 02 Mar 2011 01:15
by nas8e9
calude wrote:I tried to transform my working code to udc "openwith" which allows multiple instances but with my limited understanding of all this and the syntax being a little different I'm looking for a hand.
either a "openwith" codeline or a script that could talk to pdftk
I'm not a programmer but I wonder whether you would want to go the openwith-route: trying to start 1,300 instances at the same time feels like pushing some Windows limits.

A different approach would be to use the Report tab of the Info Panel functionality to get a text file with all file names and using a decent text editor (Notepad++, PSPad, UltraEdit, etc.) to automatically add the necessary before and after commands, e.g. by using Find and Replace to search for the new line character and replacing it with

Code: Select all

stamp watermark.pdf output result.pdf[new line character]pdftk[space]
Again, I'm not a programmer... :mrgreen:

There is a corresponding report()-scripting command which could further automate this; hopefully one of the forum members who actually knows something about scripting, can help you further.

I would, once you'd have a working script, check the errorlevel after each file to catch any Pdftk error, to prevent having to manually check 1,300 .pdf files.

Re: stamp a watermark with pdftk

Posted: 03 Mar 2011 12:01
by calude
Thanks nas8e9 for your suggestions
but I think a script would be easier to handle and could be used by others

any scriptwriter virtuoso want to join/help ??

Calude

Re: stamp a watermark with pdftk

Posted: 15 Mar 2011 09:40
by calude
nobody wants to help me bouhouhou !!!

:)

Calude

Re: stamp a watermark with pdftk

Posted: 15 Mar 2011 12:29
by zer0
calude wrote:nobody wants to help me bouhouhou !!!

:)

Calude
What kind of effort have you made? What error messages are you getting? We may be able to point you in the right direction as opposed to writing the whole thing from scratch.

Re: stamp a watermark with pdftk

Posted: 15 Mar 2011 13:29
by calude
hi
I have working code (in my first post) for one item at a time
what I'm looking for is some clues to write a script loop that will send the working code to each and every selected items one after another until all is done

Calude

Re: stamp a watermark with pdftk

Posted: 15 Mar 2011 15:29
by zer0
calude wrote:hi
I have working code (in my first post) for one item at a time
what I'm looking for is some clues to write a script loop that will send the working code to each and every selected items one after another until all is done

Calude
Have you tried foreach() to loop through the selected items? How about this...

Code: Select all

foreach($token, <get selecteditemspathnames |>) {
  open '"C:\Windows\System32\pdftk.exe" $token stamp "D:\CV_mes_documents\wm\WM1.pdf" output "D:\CV_mes_documents\wm\WM_output\<curbase>_wm.<curext>"';
}
Any luck?