Xbase++ Requires Chilkat v11.7.0+
Xbase++
Tile a Watermark Across a PDF Page
See more PDF Watermark Examples
Demonstrates a tiled watermark, which repeats the stamp over the whole page instead of placing it once. Tiling overrides position.align; tile.spacingX and spacingY set the gaps, and tile.stagger offsets alternate rows by half a tile so the pattern does not line up in columns. A faint tiled stamp carrying the name or address is the usual way to mark a document so that a leaked copy can be traced back, and zOrder back keeps it behind the text where it does not hinder reading.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oPdf
LOCAL oJson
LOCAL oJsonOut
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The PDF used in this example is available at long_report.pdf
oPdf := CreateObject("Chilkat.Pdf")
nSuccess := oPdf:LoadFile("qa_data/pdf/long_report.pdf")
IF (nSuccess == 0)
? oPdf:LastErrorText
oPdf:destroy()
RETURN
ENDIF
oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("type", "text")
// {date:FORMAT} is replaced per page when the watermark is added. The other placeholders are
// {page}, {pages} and {filename}; {{ gives a literal brace.
oJson:UpdateString("text", "jdoe@example.com {date:yyyy-MM-dd}")
oJson:UpdateString("id", "trace")
oJson:UpdateString("zOrder", "back")
oJson:UpdateNumber("font.size", "14")
oJson:UpdateNumber("opacity", "0.15")
oJson:UpdateNumber("rotation", "30")
oJson:UpdateBool("tile.enabled", 1)
oJson:UpdateNumber("tile.spacingX", "60")
oJson:UpdateNumber("tile.spacingY", "80")
oJson:UpdateBool("tile.stagger", 1)
oJsonOut := CreateObject("Chilkat.JsonObject")
nSuccess := oPdf:Watermark("add", oJson, oJsonOut)
IF (nSuccess == 0)
? oPdf:LastErrorText
oPdf:destroy()
oJson:destroy()
oJsonOut:destroy()
RETURN
ENDIF
? "id: " + oJsonOut:StringOf("id") + " pages: " + oJsonOut:StringOf("pages")
nSuccess := oPdf:WriteFile("qa_output/report_traced.pdf")
IF (nSuccess == 0)
? oPdf:LastErrorText
oPdf:destroy()
oJson:destroy()
oJsonOut:destroy()
RETURN
ENDIF
// Sample output:
// id: trace pages: 1-3
oPdf:destroy()
oJson:destroy()
oJsonOut:destroy()