Delphi DLL Requires Chilkat v11.7.0+
>, says so with placeholderSyntax, written around the word "name".
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
pdf: HCkPdf;
json: HCkJsonObject;
jsonOut: HCkJsonObject;
i: Integer;
count_i: Integer;
begin
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 := CkPdf_Create();
success := CkPdf_LoadFile(pdf,'qa_data/pdf/letter_template.pdf');
if (success = False) then
begin
Memo1.Lines.Add(CkPdf__lastErrorText(pdf));
Exit;
end;
// The letter reads: "Dear [[name]]," ... "expires on [[expiry]]" ... "[[amount]] per year" ... "[[agent]]".
json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'placeholderSyntax','[[name]]');
CkJsonObject_UpdateString(json,'placeholders.date','October 18, 2026');
CkJsonObject_UpdateString(json,'placeholders.name','Ms. Rivera');
CkJsonObject_UpdateString(json,'placeholders.expiry','December 31, 2026');
CkJsonObject_UpdateString(json,'placeholders.amount','$299.00');
CkJsonObject_UpdateString(json,'placeholders.agent','Dana Whitfield, Account Manager');
jsonOut := CkJsonObject_Create();
success := CkPdf_TextReplace(pdf,'apply',json,jsonOut);
if (success = False) then
begin
Memo1.Lines.Add('Not applied: ' + CkJsonObject__emit(jsonOut));
if (success = False) then
begin
Memo1.Lines.Add(CkPdf__lastErrorText(pdf));
Exit;
end;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jsonOut,'replacements');
while i < count_i do
begin
CkJsonObject_putI(jsonOut,i);
Memo1.Lines.Add('[[' + CkJsonObject__stringOf(jsonOut,'replacements[i].field') + ']] replaced');
i := i + 1;
end;
success := CkPdf_WriteFile(pdf,'qa_output/letter_rivera.pdf');
if (success = False) then
begin
Memo1.Lines.Add(CkPdf__lastErrorText(pdf));
Exit;
end;
// Sample output:
// [[date]] replaced
// [[name]] replaced
// [[expiry]] replaced
// [[amount]] replaced
// [[agent]] replaced
CkPdf_Dispose(pdf);
CkJsonObject_Dispose(json);
CkJsonObject_Dispose(jsonOut);