Multipage PDF watermarking
Posted: 2019-04-15T05:41:35-07:00
Hello IM people,
I'm on linux and I want to put together a command that can take a pdf from the standard input, watermark it, and write it on the standard output. I turned to ImageMagick because of all the features and also because the rasterisation of pdfs was perfect for my use case.
After skimming this forum and some other ressources, I managed to put together this command :
This does what I want, but only work for single page document. I can't find how to make it treat all the pages of a document. I know about the use of bracket to select pages, but I don't know how to apply it here.
Is it possible to do this with ImageMagick (I'm using 6.8, but could deploy 7 if necessary), or should I just split and merge the pdfs with something like pdftk ?
The latter solution would be suboptimal for me, as this would mean I would need to create temporary files, and because the pdfs are coming from and going to another machine through a http service, this would slow down the process.
I'm on linux and I want to put together a command that can take a pdf from the standard input, watermark it, and write it on the standard output. I turned to ImageMagick because of all the features and also because the rasterisation of pdfs was perfect for my use case.
After skimming this forum and some other ressources, I managed to put together this command :
Code: Select all
convert pdf:- -write mpr:base \
\( mask.png -shade 30x30 -blur 0x1 +level 45%,55% -write mpr:water +delete \) \ # create the watermark logo from a black and white image
\( +clone -tile mpr:water -draw "color 0,0 reset" -write mpr:tile +delete \) \ # tile it to the input image
+delete \
mpr:tile mpr:base \ # the order is important here, so that the compose effect can work the way I want
-compose Overlay -composite \
pdf:-
Is it possible to do this with ImageMagick (I'm using 6.8, but could deploy 7 if necessary), or should I just split and merge the pdfs with something like pdftk ?
The latter solution would be suboptimal for me, as this would mean I would need to create temporary files, and because the pdfs are coming from and going to another machine through a http service, this would slow down the process.