Tcl Requires Chilkat v11.7.0+
>, says so with placeholderSyntax, written around the word "name".
Tcl
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 Tcl Downloads
load ./chilkat.dll
set 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
set pdf [new_CkPdf]
set success [CkPdf_LoadFile $pdf "qa_data/pdf/letter_template.pdf"]
if {$success == 0} then {
puts [CkPdf_lastErrorText $pdf]
delete_CkPdf $pdf
exit
}
# The letter reads: "Dear [[name]]," ... "expires on [[expiry]]" ... "[[amount]] per year" ... "[[agent]]".
set json [new_CkJsonObject]
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"
set jsonOut [new_CkJsonObject]
set success [CkPdf_TextReplace $pdf "apply" $json $jsonOut]
if {$success == 0} then {
puts "Not applied: [CkJsonObject_emit $jsonOut]"
if {$success == 0} then {
puts [CkPdf_lastErrorText $pdf]
delete_CkPdf $pdf
delete_CkJsonObject $json
delete_CkJsonObject $jsonOut
exit
}
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jsonOut "replacements"]
while {$i < $count_i} {
CkJsonObject_put_I $jsonOut $i
puts "{[[}[CkJsonObject_stringOf $jsonOut {replacements[i].field}]]] replaced"
set i [expr $i + 1]
}
set success [CkPdf_WriteFile $pdf "qa_output/letter_rivera.pdf"]
if {$success == 0} then {
puts [CkPdf_lastErrorText $pdf]
delete_CkPdf $pdf
delete_CkJsonObject $json
delete_CkJsonObject $jsonOut
exit
}
# Sample output:
# [[date]] replaced
# [[name]] replaced
# [[expiry]] replaced
# [[amount]] replaced
# [[agent]] replaced
delete_CkPdf $pdf
delete_CkJsonObject $json
delete_CkJsonObject $jsonOut