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

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // 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

  final pdf = CkPdf();
  try {
    pdf.loadFile('qa_data/pdf/long_report.pdf');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final json = CkJsonObject();
  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);

  final jsonOut = CkJsonObject();
  try {
    pdf.watermark('add', json, jsonOut);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print('id: ${jsonOut.stringOf('id')} pages: ${jsonOut.stringOf('pages')}');

  try {
    pdf.writeFile('qa_output/report_traced.pdf');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Sample output:

  // id: trace pages: 1-3
}