Lua Requires Chilkat v11.7.0+
>, says so with placeholderSyntax, written around the word "name".
Lua
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 Lua Downloads
local chilkat = require("chilkat")
-- 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
local pdf = chilkat.Pdf.new()
local success = pdf:load_file("qa_data/pdf/letter_template.pdf")
if not success then
print(pdf.last_error_text)
return
end
-- The letter reads: "Dear [[name]]," ... "expires on [[expiry]]" ... "[[amount]] per year" ... "[[agent]]".
local json = chilkat.JsonObject.new()
json:update_string("placeholderSyntax", "[[name]]")
json:update_string("placeholders.date", "October 18, 2026")
json:update_string("placeholders.name", "Ms. Rivera")
json:update_string("placeholders.expiry", "December 31, 2026")
json:update_string("placeholders.amount", "$299.00")
json:update_string("placeholders.agent", "Dana Whitfield, Account Manager")
local jsonOut = chilkat.JsonObject.new()
success = pdf:text_replace("apply", json, jsonOut)
if not success then
print("Not applied: " .. jsonOut:emit())
if not success then
print(pdf.last_error_text)
return
end
end
local i = 0
local count_i = jsonOut:size_of_array("replacements")
while i < count_i do
jsonOut.i = i
print("[[" .. jsonOut:string_of("replacements[i].field") .. "]] replaced")
i = i + 1
end
success = pdf:write_file("qa_output/letter_rivera.pdf")
if not success then
print(pdf.last_error_text)
return
end
-- Sample output:
-- [[date]] replaced
-- [[name]] replaced
-- [[expiry]] replaced
-- [[amount]] replaced
-- [[agent]] replaced