Objective-C Requires Chilkat v11.7.0+
Objective-C
How a PDF Watermark Is Stored: artifact, annotation, layer or content
See more PDF Watermark Examples
Demonstrates the approach member, which decides how the watermark is stored and therefore what can be done with it afterwards. artifact (the default) is marked content that viewers draw, text extraction leaves out and Chilkat can remove later. annotation is a Watermark annotation, always on top, and the only approach allowed on a signed PDF while PreserveSignatures is true. layer is an optional-content layer the viewer can hide and that can be made print-only. content draws straight into the page with no marker: visible everywhere and the tamper-resistant choice, but by design it can never be listed or removed again.Chilkat Objective-C Downloads
#import <CkoJsonObject.h>
#import <CkoPdf.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 two_page_memo.pdf
CkoJsonObject *json = [[CkoJsonObject alloc] init];
CkoJsonObject *jsonOut = [[CkoJsonObject alloc] init];
CkoJsonObject *filter = [[CkoJsonObject alloc] init];
// The same watermark stored four different ways, each in its own copy of the document.
CkoPdf *pdf = [[CkoPdf alloc] init];
success = [pdf LoadFile: @"qa_data/pdf/two_page_memo.pdf"];
if (success == NO) {
NSLog(@"%@",pdf.LastErrorText);
return;
}
[json UpdateString: @"type" value: @"text"];
[json UpdateString: @"text" value: @"DRAFT"];
[json UpdateString: @"id" value: @"draft"];
[json UpdateString: @"approach" value: @"artifact"];
success = [pdf Watermark: @"add" jsonIn: json jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@",pdf.LastErrorText);
return;
}
// detect answers whether anything matching the filter is in the document. Finding nothing is
// still success: "found" is simply false.
[filter UpdateString: @"id" value: @"draft"];
success = [pdf Watermark: @"detect" jsonIn: filter jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@",pdf.LastErrorText);
return;
}
NSLog(@"%@%d",@"artifact: found = ",[jsonOut BoolOf: @"found"]);
// An annotation: always drawn on top, and the one approach a signed PDF accepts.
CkoPdf *pdf2 = [[CkoPdf alloc] init];
success = [pdf2 LoadFile: @"qa_data/pdf/two_page_memo.pdf"];
if (success == NO) {
NSLog(@"%@",pdf2.LastErrorText);
return;
}
[json UpdateString: @"approach" value: @"annotation"];
success = [pdf2 Watermark: @"add" jsonIn: json jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@",pdf2.LastErrorText);
return;
}
success = [pdf2 Watermark: @"detect" jsonIn: filter jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@",pdf2.LastErrorText);
return;
}
NSLog(@"%@%d",@"annotation: found = ",[jsonOut BoolOf: @"found"]);
// A layer, which the viewer's layers panel can switch off.
CkoPdf *pdf3 = [[CkoPdf alloc] init];
success = [pdf3 LoadFile: @"qa_data/pdf/two_page_memo.pdf"];
if (success == NO) {
NSLog(@"%@",pdf3.LastErrorText);
return;
}
[json UpdateString: @"approach" value: @"layer"];
[json UpdateString: @"layer.name" value: @"Draft marking"];
success = [pdf3 Watermark: @"add" jsonIn: json jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@",pdf3.LastErrorText);
return;
}
success = [pdf3 Watermark: @"detect" jsonIn: filter jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@",pdf3.LastErrorText);
return;
}
NSLog(@"%@%d",@"layer: found = ",[jsonOut BoolOf: @"found"]);
// Drawn into the page content with no marker. There is nothing to find afterwards, which is the
// point of it: it cannot be stripped out by a tool that removes watermarks.
CkoPdf *pdf4 = [[CkoPdf alloc] init];
success = [pdf4 LoadFile: @"qa_data/pdf/two_page_memo.pdf"];
if (success == NO) {
NSLog(@"%@",pdf4.LastErrorText);
return;
}
[json UpdateString: @"approach" value: @"content"];
success = [pdf4 Watermark: @"add" jsonIn: json jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@",pdf4.LastErrorText);
return;
}
success = [pdf4 Watermark: @"detect" jsonIn: filter jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@",pdf4.LastErrorText);
return;
}
NSLog(@"%@%d",@"content: found = ",[jsonOut BoolOf: @"found"]);
// Sample output:
// artifact: found = True
// annotation: found = True
// layer: found = True
// content: found = False