1. Products
  2.   PDF
  3.   GO
  4.   MarkPDF

Open Source Go Library for PDF Document Generation

A tiny command line tool for watermarking PDF files using image or text

MarkPDF is a simple and tiny open-source PDF document manipulation API to add text and image-based watermarks to PDF documents. The API provides a set of commands and a command line tool for document manipulation. It's pretty simple and fast to use. Using the commands, the developer can configure position, rotation, stretch and set the opacity of the PDF document.

The API is lightweight with no external dependencies. Currently, the API supported adding only images and text as watermarks in your document. While using text watermarks the API supports Courier, Helvetica, and Times Roman fonts only and while using image watermarks you can use PNG images.


Previous Next

Getting Started with MarkPDF

To install the MarkPDF on your system, you need to download the latest stable release then rename it and give it execute permission. 

Install MarkPDF via GitHub

mv markpdf_linux-amd64 markpdf 
sudo chmod +x markpdf

Generate PDF Document via Free Go Library

Generating PDF documents with Go is pretty simple. All you need to do is create a blank PDf document with A4 size by using pdf.NewPDF("A4") method of the API. You can set measurements of the document in centimeters using pdf.SetUnits("cm") method and Similarly draw a grid in the newly created PDF document using pdf.DrawUnitGrid() method.

Set Font in PDF using Free GO API

This lightweight open-source API allows basic document manipulation and generation operation for PDf documents. Once you have created a new document, you need to set font and font styles. Inorder to set fonts, pdf.SetFont() method, set position using pdf.SetXY() method and color of the text using pdf.SetColor() method respectively.

Add Image or Text Based Watermark to PDF via Go Library

The Open Source library MarkPDF allows software professionals to add text or image-based watermarks in PDF documents with just a couple of lines of code. You can easily create the image watermark by importing a pre-created company logo, stamp, or other images. Different types of settings can be applied to accomplish different watermarks styles.

Apply Image watermarking to PDF via Go

 # 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