C Requires Chilkat v11.7.0+
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 C Downloads
#include <C_CkPdf.h>
#include <C_CkJsonObject.h>
void ChilkatSample(void)
{
BOOL success;
HCkPdf pdf;
HCkJsonObject json;
HCkJsonObject 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 = CkPdf_Create();
success = CkPdf_LoadFile(pdf,"qa_data/pdf/long_report.pdf");
if (success == FALSE) {
printf("%s\n",CkPdf_lastErrorText(pdf));
CkPdf_Dispose(pdf);
return;
}
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) {
printf("%s\n",CkPdf_lastErrorText(pdf));
CkPdf_Dispose(pdf);
CkJsonObject_Dispose(json);
CkJsonObject_Dispose(jsonOut);
return;
}
printf("id: %s pages: %s\n",CkJsonObject_stringOf(jsonOut,"id"),CkJsonObject_stringOf(jsonOut,"pages"));
success = CkPdf_WriteFile(pdf,"qa_output/report_traced.pdf");
if (success == FALSE) {
printf("%s\n",CkPdf_lastErrorText(pdf));
CkPdf_Dispose(pdf);
CkJsonObject_Dispose(json);
CkJsonObject_Dispose(jsonOut);
return;
}
// Sample output:
// id: trace pages: 1-3
CkPdf_Dispose(pdf);
CkJsonObject_Dispose(json);
CkJsonObject_Dispose(jsonOut);
}