Lazarus Pascal Requires Chilkat v11.7.0+
>, says so with placeholderSyntax, written around the word "name".
Lazarus Pascal
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 Lazarus Pascal Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Pdf,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
pdf: TPdf;
json: TJsonObject;
jsonOut: TJsonObject;
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 := TPdf.Create;
success := pdf.LoadFile('qa_data/pdf/letter_template.pdf');
if (success = False) then
begin
WriteLn(pdf.LastErrorText);
Exit;
end;
// The letter reads: "Dear [[name]]," ... "expires on [[expiry]]" ... "[[amount]] per year" ... "[[agent]]".
json := TJsonObject.Create;
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 := TJsonObject.Create;
success := pdf.TextReplace('apply',json,jsonOut);
if (success = False) then
begin
WriteLn('Not applied: ' + jsonOut.Emit());
if (success = False) then
begin
WriteLn(pdf.LastErrorText);
Exit;
end;
end;
i := 0;
count_i := jsonOut.SizeOfArray('replacements');
while i < count_i do
begin
jsonOut.I := i;
WriteLn('[[' + jsonOut.StringOf('replacements[i].field') + ']] replaced');
i := i + 1;
end;
success := pdf.WriteFile('qa_output/letter_rivera.pdf');
if (success = False) then
begin
WriteLn(pdf.LastErrorText);
Exit;
end;
// Sample output:
// [[date]] replaced
// [[name]] replaced
// [[expiry]] replaced
// [[amount]] replaced
// [[agent]] replaced
pdf.Free;
json.Free;
jsonOut.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.