Sample code for 30+ languages & platforms
AutoIt 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 AutoIt Downloads

AutoIt
Local $bSuccess = 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

$oPdf = ObjCreate("Chilkat.Pdf")
$bSuccess = $oPdf.LoadFile("qa_data/pdf/letter_template.pdf")
If ($bSuccess = False) Then
    ConsoleWrite($oPdf.LastErrorText & @CRLF)
    Exit
EndIf

;  The letter reads: "Dear [[name]]," ... "expires on [[expiry]]" ... "[[amount]] per year" ... "[[agent]]".
$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateString("placeholderSyntax","[[name]]")
$oJson.UpdateString("placeholders.date","October 18, 2026")
$oJson.UpdateString("placeholders.name","Ms. Rivera")
$oJson.UpdateString("placeholders.expiry","December 31, 2026")
$oJson.UpdateString("placeholders.amount","$299.00")
$oJson.UpdateString("placeholders.agent","Dana Whitfield, Account Manager")

$oJsonOut = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oPdf.TextReplace("apply",$oJson,$oJsonOut)
If ($bSuccess = False) Then
    ConsoleWrite("Not applied: " & $oJsonOut.Emit() & @CRLF)
    If ($bSuccess = False) Then
        ConsoleWrite($oPdf.LastErrorText & @CRLF)
        Exit
    EndIf

EndIf

Local $i = 0
Local $iCount_i = $oJsonOut.SizeOfArray("replacements")
While $i < $iCount_i
    $oJsonOut.I = $i
    ConsoleWrite("[[" & $oJsonOut.StringOf("replacements[i].field") & "]] replaced" & @CRLF)
    $i = $i + 1
Wend

$bSuccess = $oPdf.WriteFile("qa_output/letter_rivera.pdf")
If ($bSuccess = False) Then
    ConsoleWrite($oPdf.LastErrorText & @CRLF)
    Exit
EndIf

;  Sample output:

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