Unicode C++ Requires Chilkat v11.7.0+
Unicode C++
Add a CONFIDENTIAL Watermark to Every Page of a PDF
See more PDF Watermark Examples
Demonstrates the simplest watermark: a line of text across every page. "rotation" set to diagonal runs the text from the bottom-left corner to the top-right, computed for each page size, and "scale" with fit page sizes it to fill 80 percent of the page. The watermark is stored as a marked artifact by default, which means viewers show it, text extraction leaves it out, and it can be found and removed again later. Nothing is written until WriteFile is called.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");
json.UpdateString(L"text",L"CONFIDENTIAL");
// An id of your own choosing, so that the watermark can be found and removed later. One is
// generated when you do not give one.
json.UpdateString(L"id",L"confidential");
json.UpdateString(L"color",L"#C00000");
json.UpdateNumber(L"opacity",L"0.25");
json.UpdateString(L"rotation",L"diagonal");
json.UpdateString(L"scale.fit",L"page");
json.UpdateNumber(L"scale.fitPercent",L"80");
CkJsonObjectW jsonOut;
success = pdf.Watermark(L"add",json,jsonOut);
if (success == false) {
wprintf(L"%s\n",pdf.lastErrorText());
return;
}
// The id, and the pages it was stamped on. "pages" defaults to all.
wprintf(L"id: %s\n",jsonOut.stringOf(L"id"));
wprintf(L"pages: %s\n",jsonOut.stringOf(L"pages"));
success = pdf.WriteFile(L"qa_output/report_confidential.pdf");
if (success == false) {
wprintf(L"%s\n",pdf.lastErrorText());
return;
}
// Sample output:
// id: confidential
// pages: 1-3
}