Initial commit
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
commit
9be7d62d59
32
README.md
Normal file
32
README.md
Normal file
@ -0,0 +1,32 @@
|
||||
# Watermark
|
||||
|
||||
> Add watermarks on your PDFs.
|
||||
|
||||
## How to use
|
||||
|
||||
```bash
|
||||
./watermark.sh <PDF FILE>
|
||||
```
|
||||
|
||||
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 <PDF FILE>-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.
|
||||
|
25
watermark.sh
Executable file
25
watermark.sh
Executable file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user