Sample code for 30+ languages & platforms
Tcl Requires Chilkat v11.7.0+

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 Tcl Downloads

Tcl

load ./chilkat.dll

set success 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

set pdf [new_CkPdf]

set success [CkPdf_LoadFile $pdf "qa_data/pdf/long_report.pdf"]
if {$success == 0} then {
    puts [CkPdf_lastErrorText $pdf]
    delete_CkPdf $pdf
    exit
}

set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "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.
CkJsonObject_UpdateString $json "text" "jdoe@example.com  {date:yyyy-MM-dd}"
CkJsonObject_UpdateString $json "id" "trace"
CkJsonObject_UpdateString $json "zOrder" "back"
CkJsonObject_UpdateNumber $json "font.size" "14"
CkJsonObject_UpdateNumber $json "opacity" "0.15"
CkJsonObject_UpdateNumber $json "rotation" "30"

CkJsonObject_UpdateBool $json "tile.enabled" 1
CkJsonObject_UpdateNumber $json "tile.spacingX" "60"
CkJsonObject_UpdateNumber $json "tile.spacingY" "80"
CkJsonObject_UpdateBool $json "tile.stagger" 1

set jsonOut [new_CkJsonObject]

set success [CkPdf_Watermark $pdf "add" $json $jsonOut]
if {$success == 0} then {
    puts [CkPdf_lastErrorText $pdf]
    delete_CkPdf $pdf
    delete_CkJsonObject $json
    delete_CkJsonObject $jsonOut
    exit
}

puts "id: [CkJsonObject_stringOf $jsonOut id] pages: [CkJsonObject_stringOf $jsonOut pages]"

set success [CkPdf_WriteFile $pdf "qa_output/report_traced.pdf"]
if {$success == 0} then {
    puts [CkPdf_lastErrorText $pdf]
    delete_CkPdf $pdf
    delete_CkJsonObject $json
    delete_CkJsonObject $jsonOut
    exit
}

#  Sample output:

#  id: trace pages: 1-3

delete_CkPdf $pdf
delete_CkJsonObject $json
delete_CkJsonObject $jsonOut