• Stars
    star
    140
  • Rank 252,200 (Top 6 %)
  • Language
    Go
  • License
    GNU Affero Genera...
  • Created over 5 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Watermark PDF files using image or text

markpdf - Watermark PDF files using image or text

A tiny command line tool for watermarking PDF files using image or text. With simple options to configure position, opacity, rotation, stretch etc.

Highlights -

  • Very simple and easy to use
  • Extreamly fast!
  • Stretching watermark image to height or weight proportionately
  • Options to adjust position, opacity, rotation of image
  • Placeholder for text watermark
  • Tile image watermark all over the page
  • Free and open source

Install

It's just a single binary file, no external dependencies. Just download the appropriate version of executable from latest release for your OS. Then rename and give it execute permission.

mv markpdf_linux-amd64 markpdf  
sudo chmod +x markpdf

If you want to install it globally (run from any directory of your system), put it in your systems $PATH directory.

sudo mv markpdf /usr/local/bin/markpdf

Done!

How to use

Image watermarking

Command options are shown in both, shorthand and full name.

# watermark with all default options (on top left corner with 50% opacity)
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf"

# watermark at center
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" --center
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" -c

# watermark at right top with 20px offset from edge and full opaque
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" --offset-x=-20 --offset-y=20 --opacity=1.0
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" -x -20 -y 20 -o 1.0

# watermark at left bottom with 100px offset and 45 degree rotation
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" --offset-x=100 --offset-y=-100 --angle=45
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" -x 100 -y -100 -a 45

# stretch full with of page at page middle, with 30% opacity
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" --scale-width-center --opacity=0.3
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" -Wo 0.3
# Note the capital "W" 

# stretch full with of page at page bottom
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" --scale-width --offset-y=-10
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" -wy -10

# Scale the image to desired percentage
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" --scale=30

# Add image as tiles all over the page
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" --tiles

# Add image as tiles with interleaved spacing
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" --tiles --spacing=20

Text watermarking

# watermark text at right top with 20px offset from edge
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" --offset-x=-20 --offset-y=20
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" -x -20 -y 20

# Place text at center with bold-italic "Times Roman" font in blue color
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" --center --font=times_bold_italic --color=0000FF
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" -cf times_bold_italic -l 0000FF

# Place text at center with large bold-italic "Times Roman" font in blue color
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" --center --font=times_bold_italic --font-size=24.0 --color=0000FF
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" -cf times_bold_italic -s 24.0 -l 0000FF

Using placeholders with text watermark

The following placeholder can be used in text watermark:

  • {{.Page}} prints the current page number
  • {{.Pages}} prints the total page numbers
  • {{.Filename}} prints name of the source file
# Using placeholders in text watermark
markpdf "path/to/083.pdf" "File: {{.Filename}} Page {{.Page}} of {{.Pages}}" "path/to/voucher_083.pdf" -x -20 -y 30

Allowed font identifiers

Currently the following font names are supported:

  • Courier: courier, courier_bold, courier_oblique, courier_bold_oblique
  • Helvetica: helvetica, helvetica_bold, helvetica_oblique, helvetica_bold_oblique
  • Times Roman: times, times_bold, times_italic, times_bold_italic

Additional notes

  • Specifying Colors: write them as 6 or 3 digit hexadecilal as used in CSS, without the #

  • --color, --font and --font-size flag has no impact for Image watermarking

  • --scale-*, --tiles and --opacity flag has no impact for Text watermarking

  • Negative offset will set content positioning from opposite side (right for offsetX and botom from offsetY)

  • Text with opacity is not supported at this moment. Instead, you can create a transperent background PNG image with your text and then use it for watermarking.

Roadmap

βœ… Draw image on every page of PDF
βœ… Configure Opacity option
βœ… Configure watermark position by X and Y offset
βœ… Allow negative values to for offset to adjust from opposite direction
βœ…οΈ Easy option for positioning image at center
βœ… Configure image rotation angle
βœ… Options to Stretch watermark to page width or height, proportionately
βœ… Options to Stretch watermark to page width or height at the middle of page
βœ… Tile Image all over the page
βœ… Render text on every page
βœ… Configure text color, style and font
⏺ Configure text opacity
βœ… Configure text rotation angle
βœ… Text placement by offset
βœ… Put text at page center

Contribute

If you fix a bug or want to add/improve a feature, and it's alligned with the focus of this tool - watermarking PDF with ease, I will be glad to accept your PR. :)

Thanks

This tool was made using the beautiful Unidoc library. Thanks and ❀️ to Unidoc.


"This is the Book about which there is no doubt, a guidance for those conscious of Allah" - Al-Quran

More Repositories

1

geek-life

The Todo List / Task Manager for Geeks in command line
Go
447
star
2

php-watermark

Add text or image Watermark on image and PDF files
PHP
123
star
3

marionette-boilerplate

Let's start the dance! This boilerplate is a ready setup for starting your next awesome javascript app in minutes. Backbone + Marionette + RequireJS + Twitter Bootstrap
JavaScript
61
star
4

merge2pdf

Merge Image and PDF files (optionally with selective pages) with lossless quality
Go
61
star
5

Kohana-Log-Viewer

Shows log files of Kohana PHP Framework with a beautiful interface
PHP
52
star
6

short-code

ShortCode generator for PHP. Create short, reversible or random, hash like codes.
PHP
29
star
7

static-pdo

Simple PHP PDO Wrapper - light, static, easy
PHP
15
star
8

bootstrap-file-field

jQuery plugin to enhance html file input to look like bootstrap button, showing image thumb and apply useful restrictions (e.g. file types, size, number of files etc.)
HTML
12
star
9

shared-checklist

Shared Checklist - Firebase Realtime Database example
HTML
6
star
10

GulpBusterBundle

Symfony Bundle to integrate gulp-buster gulp plugin. It's a cache busting utility for gulp based asset management.
PHP
5
star
11

docker-compose-laravel

Ready made development environment for Laravel 6.x using docker-compose
Dockerfile
5
star
12

jruby-swing

A small JRuby desktop app that converts a number from decimal/hex/binary/octal to decimal/hex/binary/octal formats. It's just an example of how to make Desktop application with JRuby and Swing
Ruby
4
star
13

Kohana-Twitter-Bootstrap-boilarplate

Start a Kohana project with integrated Twitter Bootstrap in minutes.
PHP
3
star
14

sf28_lte2

Symfony 2.8 with Admin LTE 2 - A boilerplate to start new project instantly with pre-built common features!
PHP
3
star
15

four-in-a-row

A Basic Four-In-A-Row Game
Go
2
star
16

magic

Magic - PSR 11 compliant tiny Dependency Injection Container
PHP
2
star
17

session-timer

A Chrome Extension to rescue your time by notifying at a configured time limit while browsing time killing sites.
JavaScript
1
star
18

slim-magic

A tiny, sample blog with Slim Framework using magic Dependency Injection Container.
PHP
1
star
19

ajaxray.marionette-boilerplate.io

This boilerplate is a ready setup for starting your next awesome javascript app in minutes.
JavaScript
1
star
20

phonegap

1
star
21

docker-slate

A slim, docker-only setup for Slate API Docs generator based on pre-built docker images
SCSS
1
star
22

PHP-Universal-Feed-Generator

PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM)
1
star