Skip to content

XinhuaSoft/WatermarkTool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

WatermarkTool

Add text watermarks to PDF files and images from the command line.

Supported input types:

  • PDF: .pdf
  • Images: .jpg, .jpeg, .png, .bmp, .tif, .tiff, .webp

Files

  • watermark_tool.py: core Python CLI
  • run_watermark.ps1: Windows wrapper (creates/activates .venv, checks dependencies, runs script, deactivates)
  • run_watermark_linux: Linux wrapper (same behavior as PowerShell wrapper)
  • requirements.txt: Python dependencies

Requirements

  • Python 3.8+

Quick Start (Windows PowerShell)

Run through the wrapper:

powershell -NoProfile -ExecutionPolicy Bypass -File .\run_watermark.ps1 "input.pdf" "output.pdf" --text "CONFIDENTIAL"

Image example:

powershell -NoProfile -ExecutionPolicy Bypass -File .\run_watermark.ps1 "photo.jpg" "photo_marked.jpg" --text "SAMPLE" --position center --opacity 0.25

Quick Start (Linux)

Make wrapper executable once:

chmod +x ./run_watermark_linux

Run:

./run_watermark_linux input.pdf output.pdf --text "CONFIDENTIAL" --position tile

Image example:

./run_watermark_linux photo.jpg photo_marked.jpg --text "SAMPLE" --position center --opacity 0.25

Direct Python Usage

Install dependencies:

python -m pip install -r requirements.txt

Run:

python watermark_tool.py input.pdf output.pdf --text "CONFIDENTIAL" --position tile
python watermark_tool.py photo.jpg photo_marked.png --text "SAMPLE" --mode image --angle 30 --color "#00AAFF"

Show help:

python watermark_tool.py --help

CLI Options

watermark_tool.py input output --text TEXT [--mode auto|pdf|image] [--font-size N] [--opacity 0..1] [--color #RRGGBB] [--angle DEG] [--position center|tile|top-left|top-right|bottom-left|bottom-right] [--margin N] [--font-path PATH]
  • input: input file path
  • output: output file path
  • --text: watermark text (required)
  • --mode: auto (default), pdf, or image
  • --font-size: font size (default: 48)
  • --opacity: transparency from 0 to 1 (default: 0.2)
  • --color: hex color (default: #DC0000)
  • --angle: rotation angle in degrees (default: 35)
  • --position: center, tile, top-left, top-right, bottom-left, bottom-right (default: tile)
  • --margin: margin for corner positions (default: 36)
  • --font-path: optional custom TTF/TTC font path (image mode)

Behavior Notes

  • In --mode auto, the tool detects PDF vs image from input extension.
  • PDF watermarking uses pypdf + reportlab.
  • Image watermarking uses Pillow.
  • For JPG/JPEG/BMP output, the image is saved as RGB.
  • If output folder does not exist, it is created automatically.

Troubleshooting

  • Missing package error: run python -m pip install -r requirements.txt
  • PowerShell policy error on Windows: use the wrapper with -ExecutionPolicy Bypass
  • Unknown input extension in auto mode: set --mode pdf or --mode image

About

Add text watermarks to PDF files and images from the command line.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors