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

Delphi DLL
var
success: Boolean;
pdf: HCkPdf;
json: HCkJsonObject;
jsonOut: HCkJsonObject;

begin
success := False;

//  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

pdf := CkPdf_Create();
success := CkPdf_LoadFile(pdf,'qa_data/pdf/long_report.pdf');
if (success = False) then
  begin
    Memo1.Lines.Add(CkPdf__lastErrorText(pdf));
    Exit;
  end;

json := CkJsonObject_Create();
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',True);
CkJsonObject_UpdateNumber(json,'tile.spacingX','60');
CkJsonObject_UpdateNumber(json,'tile.spacingY','80');
CkJsonObject_UpdateBool(json,'tile.stagger',True);

jsonOut := CkJsonObject_Create();
success := CkPdf_Watermark(pdf,'add',json,jsonOut);
if (success = False) then
  begin
    Memo1.Lines.Add(CkPdf__lastErrorText(pdf));
    Exit;
  end;
Memo1.Lines.Add('id: ' + CkJsonObject__stringOf(jsonOut,'id') + ' pages: ' + CkJsonObject__stringOf(jsonOut,'pages'));

success := CkPdf_WriteFile(pdf,'qa_output/report_traced.pdf');
if (success = False) then
  begin
    Memo1.Lines.Add(CkPdf__lastErrorText(pdf));
    Exit;
  end;

//  Sample output:

//  id: trace pages: 1-3

CkPdf_Dispose(pdf);
CkJsonObject_Dispose(json);
CkJsonObject_Dispose(jsonOut);