Sample code for 30+ languages & platforms
Delphi ActiveX Requires Chilkat v11.7.0+

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 <>, says so with placeholderSyntax, written around the word "name".

Chilkat Delphi ActiveX Downloads

Delphi ActiveX
var
success: Integer;
pdf: TChilkatPdf;
json: TChilkatJsonObject;
jsonOut: TChilkatJsonObject;
i: Integer;
count_i: Integer;

begin
success := 0;

//  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 := TChilkatPdf.Create(Self);
success := pdf.LoadFile('qa_data/pdf/letter_template.pdf');
if (success = 0) then
  begin
    Memo1.Lines.Add(pdf.LastErrorText);
    Exit;
  end;

//  The letter reads: "Dear [[name]]," ... "expires on [[expiry]]" ... "[[amount]] per year" ... "[[agent]]".
json := TChilkatJsonObject.Create(Self);
json.UpdateString('placeholderSyntax','[[name]]');
json.UpdateString('placeholders.date','October 18, 2026');
json.UpdateString('placeholders.name','Ms. Rivera');
json.UpdateString('placeholders.expiry','December 31, 2026');
json.UpdateString('placeholders.amount','$299.00');
json.UpdateString('placeholders.agent','Dana Whitfield, Account Manager');

jsonOut := TChilkatJsonObject.Create(Self);
success := pdf.TextReplace('apply',json.ControlInterface,jsonOut.ControlInterface);
if (success = 0) then
  begin
    Memo1.Lines.Add('Not applied: ' + jsonOut.Emit());
    if (success = 0) then
      begin
        Memo1.Lines.Add(pdf.LastErrorText);
        Exit;
      end;
  end;

i := 0;
count_i := jsonOut.SizeOfArray('replacements');
while i < count_i do
  begin
    jsonOut.I := i;
    Memo1.Lines.Add('[[' + jsonOut.StringOf('replacements[i].field') + ']] replaced');
    i := i + 1;
  end;

success := pdf.WriteFile('qa_output/letter_rivera.pdf');
if (success = 0) then
  begin
    Memo1.Lines.Add(pdf.LastErrorText);
    Exit;
  end;

//  Sample output:

//  [[date]] replaced
//  [[name]] replaced
//  [[expiry]] replaced
//  [[amount]] replaced
//  [[agent]] replaced