stamp a watermark with pdftk

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
calude
Posts: 355
Joined: 13 Aug 2008 10:16
Location: Switzerland
Contact:

stamp a watermark with pdftk

Post 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

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: stamp a watermark with pdftk

Post 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.

calude
Posts: 355
Joined: 13 Aug 2008 10:16
Location: Switzerland
Contact:

Re: stamp a watermark with pdftk

Post 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

calude
Posts: 355
Joined: 13 Aug 2008 10:16
Location: Switzerland
Contact:

Re: stamp a watermark with pdftk

Post by calude »

nobody wants to help me bouhouhou !!!

:)

Calude

zer0
Posts: 2676
Joined: 19 Jan 2009 20:11

Re: stamp a watermark with pdftk

Post 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.
Reporting a bug? Have a wish? Got a question? Use search - View roadmap - FAQs: Forum + XY site
Windows 7/10
Always using the latest stable two-decimal build

calude
Posts: 355
Joined: 13 Aug 2008 10:16
Location: Switzerland
Contact:

Re: stamp a watermark with pdftk

Post 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

zer0
Posts: 2676
Joined: 19 Jan 2009 20:11

Re: stamp a watermark with pdftk

Post 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?
Reporting a bug? Have a wish? Got a question? Use search - View roadmap - FAQs: Forum + XY site
Windows 7/10
Always using the latest stable two-decimal build

Post Reply