Rust Requires Chilkat v11.7.0+
>, says so with placeholderSyntax, written around the word "name".
Rust
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 Rust Downloads
let mut 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
let pdf = chilkat::Pdf::new();
success = pdf.load_file("qa_data/pdf/letter_template.pdf").is_ok();
if !success {
println!("{}", pdf.last_error_text());
return;
}
// The letter reads: "Dear [[name]]," ... "expires on [[expiry]]" ... "[[amount]] per year" ... "[[agent]]".
let json = chilkat::JsonObject::new();
let _ = json.update_string("placeholderSyntax", "[[name]]");
let _ = json.update_string("placeholders.date", "October 18, 2026");
let _ = json.update_string("placeholders.name", "Ms. Rivera");
let _ = json.update_string("placeholders.expiry", "December 31, 2026");
let _ = json.update_string("placeholders.amount", "$299.00");
let _ = json.update_string("placeholders.agent", "Dana Whitfield, Account Manager");
let json_out = chilkat::JsonObject::new();
success = pdf.text_replace("apply", &json, &json_out).is_ok();
if !success {
println!("Not applied: {}", json_out.emit().unwrap_or_default());
if !success {
println!("{}", pdf.last_error_text());
return;
}
}
let mut i = 0;
let count_i = json_out.size_of_array("replacements");
while i < count_i {
json_out.set_i(i);
println!("[[{}]] replaced", json_out.string_of("replacements[i].field").unwrap_or_default());
i = i + 1;
}
if pdf.write_file("qa_output/letter_rivera.pdf").is_err() {
println!("{}", pdf.last_error_text());
return;
}
// Sample output:
// [[date]] replaced
// [[name]] replaced
// [[expiry]] replaced
// [[amount]] replaced
// [[agent]] replaced