Unicode C++ Requires Chilkat v11.7.0+
Unicode C++
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 Unicode C++ Downloads
#include <CkPdfW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
bool 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
CkPdfW pdf;
success = pdf.LoadFile(L"qa_data/pdf/long_report.pdf");
if (success == false) {
wprintf(L"%s\n",pdf.lastErrorText());
return;
}
CkJsonObjectW json;
json.UpdateString(L"type",L"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(L"text",L"jdoe@example.com {date:yyyy-MM-dd}");
json.UpdateString(L"id",L"trace");
json.UpdateString(L"zOrder",L"back");
json.UpdateNumber(L"font.size",L"14");
json.UpdateNumber(L"opacity",L"0.15");
json.UpdateNumber(L"rotation",L"30");
json.UpdateBool(L"tile.enabled",true);
json.UpdateNumber(L"tile.spacingX",L"60");
json.UpdateNumber(L"tile.spacingY",L"80");
json.UpdateBool(L"tile.stagger",true);
CkJsonObjectW jsonOut;
success = pdf.Watermark(L"add",json,jsonOut);
if (success == false) {
wprintf(L"%s\n",pdf.lastErrorText());
return;
}
wprintf(L"id: %s pages: %s\n",jsonOut.stringOf(L"id"),jsonOut.stringOf(L"pages"));
success = pdf.WriteFile(L"qa_output/report_traced.pdf");
if (success == false) {
wprintf(L"%s\n",pdf.lastErrorText());
return;
}
// Sample output:
// id: trace pages: 1-3
}