Unicode C Requires Chilkat v11.7.0+
>, says so with placeholderSyntax, written around the word "name".
Unicode C
PDF Placeholders with Other Delimiters: [[name]]
See more PDF Text Replacement Examples
Demonstrates the "placeholderSyntax" option. Placeholders are {{name}} by default; a template written with other delimiters, such as [[name]] or <Chilkat Unicode C Downloads
#include <C_CkPdfW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkPdfW pdf;
HCkJsonObjectW json;
HCkJsonObjectW jsonOut;
int i;
int count_i;
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 letter_template.pdf
pdf = CkPdfW_Create();
success = CkPdfW_LoadFile(pdf,L"qa_data/pdf/letter_template.pdf");
if (success == FALSE) {
wprintf(L"%s\n",CkPdfW_lastErrorText(pdf));
CkPdfW_Dispose(pdf);
return;
}
// The letter reads: "Dear [[name]]," ... "expires on [[expiry]]" ... "[[amount]] per year" ... "[[agent]]".
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"placeholderSyntax",L"[[name]]");
CkJsonObjectW_UpdateString(json,L"placeholders.date",L"October 18, 2026");
CkJsonObjectW_UpdateString(json,L"placeholders.name",L"Ms. Rivera");
CkJsonObjectW_UpdateString(json,L"placeholders.expiry",L"December 31, 2026");
CkJsonObjectW_UpdateString(json,L"placeholders.amount",L"$299.00");
CkJsonObjectW_UpdateString(json,L"placeholders.agent",L"Dana Whitfield, Account Manager");
jsonOut = CkJsonObjectW_Create();
success = CkPdfW_TextReplace(pdf,L"apply",json,jsonOut);
if (success == FALSE) {
wprintf(L"Not applied: %s\n",CkJsonObjectW_emit(jsonOut));
if (success == FALSE) {
wprintf(L"%s\n",CkPdfW_lastErrorText(pdf));
CkPdfW_Dispose(pdf);
CkJsonObjectW_Dispose(json);
CkJsonObjectW_Dispose(jsonOut);
return;
}
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jsonOut,L"replacements");
while (i < count_i) {
CkJsonObjectW_putI(jsonOut,i);
wprintf(L"[[%s]] replaced\n",CkJsonObjectW_stringOf(jsonOut,L"replacements[i].field"));
i = i + 1;
}
success = CkPdfW_WriteFile(pdf,L"qa_output/letter_rivera.pdf");
if (success == FALSE) {
wprintf(L"%s\n",CkPdfW_lastErrorText(pdf));
CkPdfW_Dispose(pdf);
CkJsonObjectW_Dispose(json);
CkJsonObjectW_Dispose(jsonOut);
return;
}
// Sample output:
// [[date]] replaced
// [[name]] replaced
// [[expiry]] replaced
// [[amount]] replaced
// [[agent]] replaced
CkPdfW_Dispose(pdf);
CkJsonObjectW_Dispose(json);
CkJsonObjectW_Dispose(jsonOut);
}