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 <C_CkPdfW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkPdfW pdf;
HCkJsonObjectW json;
HCkJsonObjectW jsonOut;
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 = CkPdfW_Create();
success = CkPdfW_LoadFile(pdf,L"qa_data/pdf/long_report.pdf");
if (success == FALSE) {
wprintf(L"%s\n",CkPdfW_lastErrorText(pdf));
CkPdfW_Dispose(pdf);
return;
}
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,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.
CkJsonObjectW_UpdateString(json,L"text",L"jdoe@example.com {date:yyyy-MM-dd}");
CkJsonObjectW_UpdateString(json,L"id",L"trace");
CkJsonObjectW_UpdateString(json,L"zOrder",L"back");
CkJsonObjectW_UpdateNumber(json,L"font.size",L"14");
CkJsonObjectW_UpdateNumber(json,L"opacity",L"0.15");
CkJsonObjectW_UpdateNumber(json,L"rotation",L"30");
CkJsonObjectW_UpdateBool(json,L"tile.enabled",TRUE);
CkJsonObjectW_UpdateNumber(json,L"tile.spacingX",L"60");
CkJsonObjectW_UpdateNumber(json,L"tile.spacingY",L"80");
CkJsonObjectW_UpdateBool(json,L"tile.stagger",TRUE);
jsonOut = CkJsonObjectW_Create();
success = CkPdfW_Watermark(pdf,L"add",json,jsonOut);
if (success == FALSE) {
wprintf(L"%s\n",CkPdfW_lastErrorText(pdf));
CkPdfW_Dispose(pdf);
CkJsonObjectW_Dispose(json);
CkJsonObjectW_Dispose(jsonOut);
return;
}
wprintf(L"id: %s pages: %s\n",CkJsonObjectW_stringOf(jsonOut,L"id"),CkJsonObjectW_stringOf(jsonOut,L"pages"));
success = CkPdfW_WriteFile(pdf,L"qa_output/report_traced.pdf");
if (success == FALSE) {
wprintf(L"%s\n",CkPdfW_lastErrorText(pdf));
CkPdfW_Dispose(pdf);
CkJsonObjectW_Dispose(json);
CkJsonObjectW_Dispose(jsonOut);
return;
}
// Sample output:
// id: trace pages: 1-3
CkPdfW_Dispose(pdf);
CkJsonObjectW_Dispose(json);
CkJsonObjectW_Dispose(jsonOut);
}