PowerShell Requires Chilkat v11.7.0+
>, says so with placeholderSyntax, written around the word "name".
PowerShell
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 PowerShell Downloads
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"
$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 = New-Object Chilkat.Pdf
$success = $pdf.LoadFile("qa_data/pdf/letter_template.pdf")
if ($success -eq $false) {
$($pdf.LastErrorText)
exit
}
# The letter reads: "Dear [[name]]," ... "expires on [[expiry]]" ... "[[amount]] per year" ... "[[agent]]".
$json = New-Object Chilkat.JsonObject
$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 = New-Object Chilkat.JsonObject
$success = $pdf.TextReplace("apply",$json,$jsonOut)
if ($success -eq $false) {
$("Not applied: " + $jsonOut.Emit())
if ($success -eq $false) {
$($pdf.LastErrorText)
exit
}
}
$i = 0
$count_i = $jsonOut.SizeOfArray("replacements")
while ($i -lt $count_i) {
$jsonOut.I = $i
$("[[" + $jsonOut.StringOf("replacements[i].field") + "]] replaced")
$i = $i + 1
}
$success = $pdf.WriteFile("qa_output/letter_rivera.pdf")
if ($success -eq $false) {
$($pdf.LastErrorText)
exit
}
# Sample output:
# [[date]] replaced
# [[name]] replaced
# [[expiry]] replaced
# [[amount]] replaced
# [[agent]] replaced