Objective-C Requires Chilkat v11.7.0+
>, says so with placeholderSyntax, written around the word "name".
Objective-C
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 Objective-C Downloads
#import <CkoPdf.h>
#import <CkoJsonObject.h>
BOOL success = NO;
// 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
CkoPdf *pdf = [[CkoPdf alloc] init];
success = [pdf LoadFile: @"qa_data/pdf/letter_template.pdf"];
if (success == NO) {
NSLog(@"%@",pdf.LastErrorText);
return;
}
// The letter reads: "Dear [[name]]," ... "expires on [[expiry]]" ... "[[amount]] per year" ... "[[agent]]".
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"placeholderSyntax" value: @"[[name]]"];
[json UpdateString: @"placeholders.date" value: @"October 18, 2026"];
[json UpdateString: @"placeholders.name" value: @"Ms. Rivera"];
[json UpdateString: @"placeholders.expiry" value: @"December 31, 2026"];
[json UpdateString: @"placeholders.amount" value: @"$299.00"];
[json UpdateString: @"placeholders.agent" value: @"Dana Whitfield, Account Manager"];
CkoJsonObject *jsonOut = [[CkoJsonObject alloc] init];
success = [pdf TextReplace: @"apply" jsonIn: json jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@%@",@"Not applied: ",[jsonOut Emit]);
if (success == NO) {
NSLog(@"%@",pdf.LastErrorText);
return;
}
}
int i = 0;
int count_i = [[jsonOut SizeOfArray: @"replacements"] intValue];
while (i < count_i) {
jsonOut.I = [NSNumber numberWithInt: i];
NSLog(@"%@%@%@",@"[[",[jsonOut StringOf: @"replacements[i].field"],@"]] replaced");
i = i + 1;
}
success = [pdf WriteFile: @"qa_output/letter_rivera.pdf"];
if (success == NO) {
NSLog(@"%@",pdf.LastErrorText);
return;
}
// Sample output:
// [[date]] replaced
// [[name]] replaced
// [[expiry]] replaced
// [[amount]] replaced
// [[agent]] replaced