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

Lazarus Pascal
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Pdf,
  Chilkat.JsonObject;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  pdf: TPdf;
  json: TJsonObject;
  jsonOut: TJsonObject;

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 := TPdf.Create;
  success := pdf.LoadFile('qa_data/pdf/long_report.pdf');
  if (success = False) then
    begin
      WriteLn(pdf.LastErrorText);
      Exit;
    end;

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

  json.UpdateBool('tile.enabled',True);
  json.UpdateNumber('tile.spacingX','60');
  json.UpdateNumber('tile.spacingY','80');
  json.UpdateBool('tile.stagger',True);

  jsonOut := TJsonObject.Create;
  success := pdf.Watermark('add',json,jsonOut);
  if (success = False) then
    begin
      WriteLn(pdf.LastErrorText);
      Exit;
    end;
  WriteLn('id: ' + jsonOut.StringOf('id') + ' pages: ' + jsonOut.StringOf('pages'));

  success := pdf.WriteFile('qa_output/report_traced.pdf');
  if (success = False) then
    begin
      WriteLn(pdf.LastErrorText);
      Exit;
    end;

  //  Sample output:

  //  id: trace pages: 1-3


  pdf.Free;
  json.Free;
  jsonOut.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.