Sample code for 30+ languages & platforms
PowerBuilder 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 PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Pdf
oleobject loo_Json
oleobject loo_JsonOut

li_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

loo_Pdf = create oleobject
li_rc = loo_Pdf.ConnectToNewObject("Chilkat.Pdf")
if li_rc < 0 then
    destroy loo_Pdf
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_Pdf.LoadFile("qa_data/pdf/long_report.pdf")
if li_Success = 0 then
    Write-Debug loo_Pdf.LastErrorText
    destroy loo_Pdf
    return
end if

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.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.
loo_Json.UpdateString("text","jdoe@example.com  {date:yyyy-MM-dd}")
loo_Json.UpdateString("id","trace")
loo_Json.UpdateString("zOrder","back")
loo_Json.UpdateNumber("font.size","14")
loo_Json.UpdateNumber("opacity","0.15")
loo_Json.UpdateNumber("rotation","30")

loo_Json.UpdateBool("tile.enabled",1)
loo_Json.UpdateNumber("tile.spacingX","60")
loo_Json.UpdateNumber("tile.spacingY","80")
loo_Json.UpdateBool("tile.stagger",1)

loo_JsonOut = create oleobject
li_rc = loo_JsonOut.ConnectToNewObject("Chilkat.JsonObject")

li_Success = loo_Pdf.Watermark("add",loo_Json,loo_JsonOut)
if li_Success = 0 then
    Write-Debug loo_Pdf.LastErrorText
    destroy loo_Pdf
    destroy loo_Json
    destroy loo_JsonOut
    return
end if

Write-Debug "id: " + loo_JsonOut.StringOf("id") + " pages: " + loo_JsonOut.StringOf("pages")

li_Success = loo_Pdf.WriteFile("qa_output/report_traced.pdf")
if li_Success = 0 then
    Write-Debug loo_Pdf.LastErrorText
    destroy loo_Pdf
    destroy loo_Json
    destroy loo_JsonOut
    return
end if

//  Sample output:

//  id: trace pages: 1-3


destroy loo_Pdf
destroy loo_Json
destroy loo_JsonOut