Stamps#

Creating Stamps#

Stamps can be created with the Stamp type annotation.

To set the kind of stamp you need refer to the icon names against the Stamp icon type and define it with the setIcon() method.

EXAMPLE

let fileData = fs.readFileSync("test.pdf")

let document = mupdfjs.PDFDocument.openDocument(fileData, "application/pdf")
let page = document.loadPage(0)
let annotation = page.createAnnotation("Stamp")
annotation.setIcon("Draft")
annotation.setRect([0, 0, 50, 50])
annotation.update()

fs.writeFileSync("output-stamp.pdf", document.saveToBuffer("incremental").asUint8Array())

Note

The rectangle you define for the stamp annotation will always maintain the correct aspect ratio for the stamp, thus if a square sized rectangle with e.g. [0,0,50,50] is defined the stamp annotation may recalculate the [ulx,uly,lrx,lry] according to the aspect ratio of the stamp type and then use that to work out the corresponding lrx or lry value, therefore, for example the actual rectangle might become [0,0,200,50].


Code samples

Code samples are in TypeScript and assume that the following requirements are defined in your TypeScript file header as follows:

import * as fs from "fs"
import * as mupdfjs from "mupdf/mupdfjs"