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

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Pdf
oleobject loo_Json
oleobject loo_JsonOut
long i
long li_Count_i

li_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

loo_Pdf = create oleobject
li_rc = loo_Pdf.ConnectToNewObject("Chilkat.Pdf")
if li_rc < 0 then
    destroy loo_Pdf
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_Pdf.LoadFile("qa_data/pdf/letter_template.pdf")
if li_Success = 0 then
    Write-Debug loo_Pdf.LastErrorText
    destroy loo_Pdf
    return
end if

//  The letter reads: "Dear [[name]]," ... "expires on [[expiry]]" ... "[[amount]] per year" ... "[[agent]]".
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.UpdateString("placeholderSyntax","[[name]]")
loo_Json.UpdateString("placeholders.date","October 18, 2026")
loo_Json.UpdateString("placeholders.name","Ms. Rivera")
loo_Json.UpdateString("placeholders.expiry","December 31, 2026")
loo_Json.UpdateString("placeholders.amount","$299.00")
loo_Json.UpdateString("placeholders.agent","Dana Whitfield, Account Manager")

loo_JsonOut = create oleobject
li_rc = loo_JsonOut.ConnectToNewObject("Chilkat.JsonObject")

li_Success = loo_Pdf.TextReplace("apply",loo_Json,loo_JsonOut)
if li_Success = 0 then
    Write-Debug "Not applied: " + loo_JsonOut.Emit()
    if li_Success = 0 then
        Write-Debug loo_Pdf.LastErrorText
        destroy loo_Pdf
        destroy loo_Json
        destroy loo_JsonOut
        return
    end if

end if

i = 0
li_Count_i = loo_JsonOut.SizeOfArray("replacements")
do while i < li_Count_i
    loo_JsonOut.I = i
    Write-Debug "[[" + loo_JsonOut.StringOf("replacements[i].field") + "]] replaced"
    i = i + 1
loop

li_Success = loo_Pdf.WriteFile("qa_output/letter_rivera.pdf")
if li_Success = 0 then
    Write-Debug loo_Pdf.LastErrorText
    destroy loo_Pdf
    destroy loo_Json
    destroy loo_JsonOut
    return
end if

//  Sample output:

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


destroy loo_Pdf
destroy loo_Json
destroy loo_JsonOut