Markpdf - 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
  • 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

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

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-* 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

Owner
Anis uddin Ahmad
I am a web application architect, proficient at requirement analysis, sophisticated solution design and scalable application development.
Anis uddin Ahmad
Comments
  • Add text watermark with template

    Add text watermark with template

    Builds on top of https://github.com/ajaxray/markpdf/pull/14 with feedback from @ajaxray in mind

    Approach:

    1. Check if given watermark is a template with isWatermarkATemplate
    2. If a template, dynamically change the text in Paragraph object by after executing template in iteration.
    3. else, rely on static-text and continue with old behavior without doing extra work or creating extra objects.
  • [Feature] Image tiles all over the page

    [Feature] Image tiles all over the page

    Synatax:

    markpdf pdf.pdf ~/Downloads/logo.jpeg out.pdf -p10 -t
    

    In above syntax, using -p to scale the image to 10% and -t to generate tiles all over the page. Result: pattern like below: image

    You can also use an additional flag -z or --spacing to add spacing b/w the tiles.

    markpdf pdf.pdf ~/Downloads/logo.jpeg out.pdf -p10 -t -z20
    
    image
  • Compilation issue

    Compilation issue

    As-Salamu Alaikum,

    $ go build -ldflags=-s .

    github.com/unidoc/unidoc/pdf/model

    C:\Users\0wner\go\src\github.com\unidoc\unidoc\pdf\model\writer.go:538:12: constant 4294967295 overflows int

    How do proceed?

    Thanks in advance.

  • Text Opacity not working like image opacity.

    Text Opacity not working like image opacity.

    Hello @ajaxray ,

    I'm using the command "markpdf "test_text.pdf" "Approved, Not published" "/var/www/html/test_text_out.pdf" -c -s 20.0 -a 45 -o 0.5" for add text as watermark, but the watermark is very dark. I also change opacity 0.1 but in both cases, the watermark looks the same. test_text.pdf

    But in the case of an image it's work fine.

    Thank You In advance

  • Open source?

    Open source?

    Hi,

    You state that this is open source, but when I compiled this it required a unidoc dependency from Github. Although your built binaries work fine, when I compile it now, a watermark is added to the file from Unidoc and a license error is thrown.

    I was trying to introduce a configuration option so that the watermark was only applied to the first page, but now this isn't possible.

    Is this something you can revise?

  • How to add new line in text placeholder?

    How to add new line in text placeholder?

    I am trying to add 2 lines(rows or line break) placeholder. I am using php to call command and trying to add new line "\n".

    It gives no error and also no placeholder added in pdf. If I remove new line chars it works but in one line.

    Is there any way I can add 2 lines as text placeholder?

  • Apple Silicon

    Apple Silicon

    Maybe I'm missing something, but is there a way to build this for Apple Silicon? I see the Darwin build, but it is not for ARM 64 as far as I can tell. Same goes for the build.sh. No way to build for Darwin + Arm

  • Avira Security Alert

    Avira Security Alert

    Hi,

    I have a security problem running the program. I am using Windows 10 + Avira Free Security v1.1.57.24596.

    Steps to reproduce:

    1. Download a release for Windows: Releases > markpdf_windows-386.exe
    2. Set appropriate execution permissions
    3. Run markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf"
    4. The popup below appears from Avira

    image

  • MarkPDF working in terminal but not in Laravel > Process

    MarkPDF working in terminal but not in Laravel > Process

    Hi,

    hopelly someone can help because this bug is driving me crazy.

    Initially everything worked fine until few weeks ago. I have updated markpdf with the latest version.

    When i use process, the isSuccessful() returns true, But the file is not modified.

    When i use the exact same options as in process but paste this in the terminal. Then the file is modified correctly.

    This is driving me nuts because i can't make it to work with process and cant see any error messages.

    Hopelly someone has an answer.

  • added flag to scale image to desired percentage

    added flag to scale image to desired percentage

    @ajaxray Added support to add scale / p flag to scale watermark image to desired percentage. Currently this package only has support to either scale image to full page-height or page-width, but not to scale relative to image itself. This is especially handy while handling bigger images in watermark (like original logos) which are bigger in size and we may want to scale it to lower dimensions.

    Usage: add flag : -p 30 or --scale 50 to scale to 50% of original size of watermark image.

  • invalid media box causes output to be all blank

    invalid media box causes output to be all blank

    I have a PDF file that seems to have an invalid media box. The file opens fine using Adobe PDF reader, so I assume there's a standard default being used.

    I can't provide the original file since it has sensitive information on it, and when I edit it, it "corrects" for the error.

    I do I have a verbose output capture, and I can provide the output PDF.

    markpdf bad.pdf "Test" bad_output.pdf --opacity=1 --font-size=12 --offset-x=10 --offset-y=10 -v
    2023/01/03 14:30:05 Input PDF: bad.pdf
    2023/01/03 14:30:05 No file exists at: Test, assuming Text Watermark.
    [DEBUG]  parser.go:1530 Pdf version 1.7
    [DEBUG]  main.go:131 Failed to get page mediabox: Invalid media box
    2023/01/03 14:30:05 Page Width       : 0
    2023/01/03 14:30:05 Page Height      : 0
    2023/01/03 14:30:05 Paragraph width: 19.450000
    2023/01/03 14:30:05 Paragraph height: 10.000000
    2023/01/03 14:30:05 Offsets x: 10.000000, y: 10.000000
    

    bad_output.pdf

    I'll see if I can get the source code to work and hard-code some values and see if that makes a difference.

  • In-document bookmarks and links are removed once marked with this tool

    In-document bookmarks and links are removed once marked with this tool

    I have found that if I have a PDF document that has bookmarks and links for easy navigation, all of them are removed once I mark my PDF using this tool. Hope that a fix could be implemented so the marked PDF will preserve the bookmarks and links it originally contained. Thanks in advanced!

  • Watermark position ignored

    Watermark position ignored

    I specify -x -10 -y -10 as position to have watermark to the bottom right but with some pdf documents the tool doesn't respect the position specified and moves the watermark to the top right. Why does this happen?

A PDF document generator with high level support for text, drawing and images

GoFPDF document generator Package go-pdf/fpdf implements a PDF document generator with high level support for text, drawing and images. Features UTF-8

Jan 4, 2023
Golang wrapper for Exiftool : extract as much metadata as possible (EXIF, ...) from files (pictures, pdf, office documents, ...)

go-exiftool go-exiftool is a golang library that wraps ExifTool. ExifTool's purpose is to extract as much metadata as possible (EXIF, IPTC, XMP, GPS,

Dec 28, 2022
A Docker-powered stateless API for PDF files.
A Docker-powered stateless API for PDF files.

Gotenberg provides a developer-friendly API to interact with powerful tools like Chromium and LibreOffice to convert many documents (HTML, Markdown, Word, Excel, etc.) to PDF, transform them, merge them, and more!

Dec 30, 2022
Split text files into gzip files with x lines

hakgzsplit split lines of text into multiple gzip files

Jun 21, 2022
A PDF processor written in Go.
A PDF processor written in Go.

pdfcpu: a Go PDF processor pdfcpu is a PDF processing library written in Go supporting encryption. It provides both an API and a CLI. Supported are al

Jan 8, 2023
A simple library for generating PDF written in Go lang

gopdf gopdf is a simple library for generating PDF document written in Go lang. Features Unicode subfont embedding. (Chinese, Japanese, Korean, etc.)

Jan 3, 2023
PDF tools for reMarkable tablets

rm-pdf-tools - PDF tools for reMarkable Disclaimer: rm-pdf-tools is currently in a very early version, bugs are to be expected. Furthermore, the inten

Oct 14, 2022
A command line tool for mainly exporting logbook records from Google Spreadsheet to PDF file in EASA format
A command line tool for mainly exporting logbook records from Google Spreadsheet to PDF file in EASA format

Logbook CLI This is a command line tool for mainly exporting logbook records from Google Spreadsheet to PDF file in EASA format. It also supports rend

Feb 6, 2022
PDF file parser

#pdf A pdf document parsing and modifying library The libary provides functions to parse and show elements in PDF documents. It checks the validity

Nov 7, 2021
create PDF from ASCII File for Cable labels

CableLable create PDF from ASCII File for Cable labels file format is one label per line, a line containing up to 3 words, each word is a line on the

Nov 8, 2021
Convert document to pdf with golang

Convert document to pdf Build docker: docker build --pull --rm -f "Dockerfile" -t convertdocument:latest "." docker run -p 3000:3000 registry.gitlab.

Nov 29, 2021
Ghostinthepdf - This is a small tool that helps to embed a PostScript file into a PDF

This is a small tool that helps to embed a PostScript file into a PDF in a way that GhostScript will run the PostScript code during the

Dec 20, 2022
Read data from rss, convert in pdf and send to kindle. Amazon automatically convert them in azw3.

Kindle-RSS-PDF-AZW3 The Kindle RSS PDF AZW3 is a personal project. The Kindle RSS PDF AZW3 is a personal project. I received a Kindle for Christmas, a

Jan 10, 2022
Go-wk - PDF Generation API with wkhtmltopdf

Simple PDF Generation API with wkhtmltopdf Quick start Clone the repo locally an

Jan 25, 2022
Newser is a simple utility to generate a pdf with you favorite news articles
Newser is a simple utility to generate a pdf with you favorite news articles

Newser A simple utility to crawl some news sites or other resources and download content into a pdf Building Make sure you have config.yaml setup and

Nov 9, 2022
PDF Annotator of Nightmares 🎃
PDF Annotator of Nightmares 🎃

PDFrankenstein is a GUI tool that intends to fill the gap on Linux where a good capable PDF annotator like Adobe Acrobat does not exist. What can you

Dec 8, 2022
Easily create Go files from stub files

go-stubs Easily create .go files from stub files in your projects. Usage go get github.com/nwby/go-stubs Create a stub file: package stubs type {{.Mo

Jan 27, 2022
app-services-go-linter plugin analyze source tree of Go files and validates the availability of i18n strings in *.toml files

app-services-go-linter app-services-go-linter plugin analyze source tree of Go files and validates the availability of i18n strings in *.toml files. A

Nov 29, 2021