Objective-C Requires Chilkat v11.7.0+
Objective-C
Find Out Whether a PDF Has a Watermark
See more PDF Watermark Examples
Demonstrates detect, which answers yes or no, and list, which enumerates what is there. Both recognize the watermarks Chilkat writes and the standard forms other tools write: Watermark annotations from any producer, marked content tagged as a Watermark or Background artifact, Acrobat watermarks and backgrounds, and optional-content layers whose name says watermark. Acrobat headers and footers are not watermarks and are ignored. A watermark from another producer has no id of its own, so Chilkat assigns one (ext1, ext2, ...) that stays valid until the PDF is changed, which is what makes a list followed by a remove by id work. Properties that cannot be read back are left out rather than guessed.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 acrobat_two_watermarks.pdf
CkoPdf *pdf = [[CkoPdf alloc] init];
success = [pdf LoadFile: @"qa_data/pdf/acrobat_two_watermarks.pdf"];
if (success == NO) {
NSLog(@"%@",pdf.LastErrorText);
return;
}
// An empty filter means every watermark in the document.
CkoJsonObject *filter = [[CkoJsonObject alloc] init];
CkoJsonObject *jsonOut = [[CkoJsonObject alloc] init];
success = [pdf Watermark: @"detect" jsonIn: filter jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@",pdf.LastErrorText);
return;
}
NSLog(@"%@%d%@%d",@"found: ",[jsonOut BoolOf: @"found"],@" count: ",[[jsonOut IntOf: @"count"] intValue]);
success = [pdf Watermark: @"list" jsonIn: filter jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@",pdf.LastErrorText);
return;
}
int i = 0;
int count_i = [[jsonOut SizeOfArray: @"watermarks"] intValue];
while (i < count_i) {
jsonOut.I = [NSNumber numberWithInt: i];
NSLog(@"%@%@",@"id: ",[jsonOut StringOf: @"watermarks[i].id"]);
NSLog(@"%@%@",@" source: ",[jsonOut StringOf: @"watermarks[i].source"]);
NSLog(@"%@%@",@" approach: ",[jsonOut StringOf: @"watermarks[i].approach"]);
NSLog(@"%@%@",@" type: ",[jsonOut StringOf: @"watermarks[i].type"]);
NSLog(@"%@%@",@" text: ",[jsonOut StringOf: @"watermarks[i].text"]);
NSLog(@"%@%@",@" pages: ",[jsonOut StringOf: @"watermarks[i].pages"]);
NSLog(@"%@%@",@" zOrder: ",[jsonOut StringOf: @"watermarks[i].zOrder"]);
NSLog(@"%@%d",@" removable: ",[jsonOut BoolOf: @"watermarks[i].removable"]);
i = i + 1;
}
// The filter narrows what is reported: by producer (chilkat, acrobat or other), by approach, by
// pages, by an exact id or label, or by text with textContains.
CkoJsonObject *bySource = [[CkoJsonObject alloc] init];
[bySource UpdateString: @"source" value: @"acrobat"];
success = [pdf Watermark: @"detect" jsonIn: bySource jsonOut: jsonOut];
if (success == NO) {
NSLog(@"%@",pdf.LastErrorText);
return;
}
NSLog(@"%@%d",@"made by Acrobat: ",[[jsonOut IntOf: @"count"] intValue]);
// Sample output:
// found: True count: 2
// id: ext1
// source: acrobat
// approach: artifact
// type: image
// text:
// pages: 1
// zOrder: front
// removable: True
// id: ext2
// source: acrobat
// approach: artifact
// type: text
// text: sample
// pages: 1
// zOrder: front
// removable: True
// made by Acrobat: 2