commit 9be7d62d592cd500234486360b61b723a514df8e Author: Louis Vallat Date: Wed Dec 15 18:56:10 2021 +0100 Initial commit Signed-off-by: Louis Vallat diff --git a/README.md b/README.md new file mode 100644 index 0000000..475f4da --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# Watermark + +> Add watermarks on your PDFs. + +## How to use + +```bash +./watermark.sh +``` + +You can watermark multiple PDFs by using the `find` command, such as : + +```bash +find ./folder -name "*.pdf" -exec ./watermark.sh {} \; +``` + +The watermarked PDF is named -out.pdf. The original one is not deleted. + +## How it works + +First it creates the watermark in a specific file, then it exports the PDF in +multiple PNGs, and watermark each extracted page, still in the PNG format so it +cannot be then edited or modified (easily) using some PDF editing software. + +The script is pretty short and straightforward to read, you can adapt without +much difficulties I believe. + +## Additional notes + +This was part of a personnal project that wasn't supposed to be made public, so +excuse the lack of comments and code dirtiness. + diff --git a/watermark.sh b/watermark.sh new file mode 100755 index 0000000..352daf1 --- /dev/null +++ b/watermark.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +WATERMARK_TEXT="VOTRE TEXTE À WATERMARKER" +COLOR="red" +INPUT_PDF="$1" +OUTPUT_PNGs="./pdf" +WATERMARK_SIZE=50 +WATERMARK_PNG_SIZE="800x300" + +convert -size ${WATERMARK_PNG_SIZE} xc:white -font Arial -pointsize ${WATERMARK_SIZE} \ + -gravity NorthWest -draw "fill ${COLOR} text 70,15 '${WATERMARK_TEXT}'" \ + -gravity SouthEast -draw "fill ${COLOR} text 70,150 '${WATERMARK_TEXT}'" \ + stamp.png + +pdftoppm ${INPUT_PDF} ${OUTPUT_PNGs} -png + +for pic in *.png; do + if [ ${pic} != "stamp.png" ]; then + composite -dissolve 25% -tile stamp.png ${pic} ${pic//.png}-marked.png + fi +done + +convert *-marked.png ${INPUT_PDF}-out.pdf +rm *.png +