Ver Fonte

PDFSamples(iOS)-Watermark、 background和headerfooter samples的完成

yangliuhua há 1 ano atrás
pai
commit
686578b976

+ 46 - 0
Samples/Samples.xcodeproj/project.pbxproj

@@ -27,6 +27,10 @@
 		C97699852A57E56900187038 /* CImageExtractViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C97699842A57E56900187038 /* CImageExtractViewController.m */; };
 		C97699892A5800A100187038 /* CTextExtractViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C97699882A5800A100187038 /* CTextExtractViewController.m */; };
 		C976998D2A580D0400187038 /* CDocumentInfoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C976998C2A580D0400187038 /* CDocumentInfoViewController.m */; };
+		C97699912A581BA900187038 /* CWatermarkViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C97699902A581BA900187038 /* CWatermarkViewController.m */; };
+		C97699932A5A5BAC00187038 /* Logo.png in Resources */ = {isa = PBXBuildFile; fileRef = C97699922A5A5BAC00187038 /* Logo.png */; };
+		C97699982A5AAEF900187038 /* CBackgroundViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C97699972A5AAEF900187038 /* CBackgroundViewController.m */; };
+		C976999C2A5ACAAB00187038 /* CHeaderFooterViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C976999B2A5ACAAB00187038 /* CHeaderFooterViewController.m */; };
 		C9E361142A5273BC004D31BE /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C9E361132A5273BC004D31BE /* AppDelegate.m */; };
 		C9E361172A5273BC004D31BE /* SceneDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C9E361162A5273BC004D31BE /* SceneDelegate.m */; };
 		C9E3611A2A5273BC004D31BE /* CSamplesFuctionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C9E361192A5273BC004D31BE /* CSamplesFuctionViewController.m */; };
@@ -88,6 +92,13 @@
 		C97699882A5800A100187038 /* CTextExtractViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CTextExtractViewController.m; sourceTree = "<group>"; };
 		C976998B2A580D0400187038 /* CDocumentInfoViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CDocumentInfoViewController.h; sourceTree = "<group>"; };
 		C976998C2A580D0400187038 /* CDocumentInfoViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CDocumentInfoViewController.m; sourceTree = "<group>"; };
+		C976998F2A581BA900187038 /* CWatermarkViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CWatermarkViewController.h; sourceTree = "<group>"; };
+		C97699902A581BA900187038 /* CWatermarkViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CWatermarkViewController.m; sourceTree = "<group>"; };
+		C97699922A5A5BAC00187038 /* Logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Logo.png; sourceTree = "<group>"; };
+		C97699962A5AAEF900187038 /* CBackgroundViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CBackgroundViewController.h; sourceTree = "<group>"; };
+		C97699972A5AAEF900187038 /* CBackgroundViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CBackgroundViewController.m; sourceTree = "<group>"; };
+		C976999A2A5ACAAA00187038 /* CHeaderFooterViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CHeaderFooterViewController.h; sourceTree = "<group>"; };
+		C976999B2A5ACAAB00187038 /* CHeaderFooterViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CHeaderFooterViewController.m; sourceTree = "<group>"; };
 		C995A2E42A53FEAD00762127 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 		C9E3610F2A5273BC004D31BE /* Samples.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Samples.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		C9E361122A5273BC004D31BE /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
@@ -140,6 +151,7 @@
 		C97699552A5534BF00187038 /* TestFile */ = {
 			isa = PBXGroup;
 			children = (
+				C97699922A5A5BAC00187038 /* Logo.png */,
 				C97699742A569AA400187038 /* CreateAnnotationTest.pdf */,
 				C97699722A566F3E00187038 /* Bird.wav */,
 				C976996C2A55868100187038 /* CommonFivePage.pdf */,
@@ -244,6 +256,33 @@
 			path = DocumentInfo;
 			sourceTree = "<group>";
 		};
+		C976998E2A581B7600187038 /* Watermark */ = {
+			isa = PBXGroup;
+			children = (
+				C976998F2A581BA900187038 /* CWatermarkViewController.h */,
+				C97699902A581BA900187038 /* CWatermarkViewController.m */,
+			);
+			path = Watermark;
+			sourceTree = "<group>";
+		};
+		C97699952A5AAEB100187038 /* Background */ = {
+			isa = PBXGroup;
+			children = (
+				C97699962A5AAEF900187038 /* CBackgroundViewController.h */,
+				C97699972A5AAEF900187038 /* CBackgroundViewController.m */,
+			);
+			path = Background;
+			sourceTree = "<group>";
+		};
+		C97699992A5ACA7700187038 /* HeaderFooter */ = {
+			isa = PBXGroup;
+			children = (
+				C976999A2A5ACAAA00187038 /* CHeaderFooterViewController.h */,
+				C976999B2A5ACAAB00187038 /* CHeaderFooterViewController.m */,
+			);
+			path = HeaderFooter;
+			sourceTree = "<group>";
+		};
 		C9E361062A5273BC004D31BE = {
 			isa = PBXGroup;
 			children = (
@@ -285,6 +324,9 @@
 				C97699822A57E54700187038 /* ImageExtract */,
 				C97699862A57FE5600187038 /* TextExtract */,
 				C976998A2A580CBE00187038 /* DocumentInfo */,
+				C97699952A5AAEB100187038 /* Background */,
+				C976998E2A581B7600187038 /* Watermark */,
+				C97699992A5ACA7700187038 /* HeaderFooter */,
 				C9E3611B2A5273BC004D31BE /* Main.storyboard */,
 				C9E3611E2A5273BF004D31BE /* Assets.xcassets */,
 				C995A2E42A53FEAD00762127 /* Info.plist */,
@@ -378,6 +420,7 @@
 				C976995D2A5534BF00187038 /* developer_guide_ios.pdf in Resources */,
 				C976995A2A5534BF00187038 /* Form_Widgets_Test.pdf in Resources */,
 				C976996D2A55868100187038 /* CommonFivePage.pdf in Resources */,
+				C97699932A5A5BAC00187038 /* Logo.png in Resources */,
 				C97699752A569AA400187038 /* CreateAnnotationTest.pdf in Resources */,
 				C9E3613B2A53AD60004D31BE /* CSamplesBaseViewController.xib in Resources */,
 				C9E3611D2A5273BC004D31BE /* Main.storyboard in Resources */,
@@ -396,12 +439,15 @@
 				C97699812A579FEC00187038 /* CPDFPageViewController.m in Sources */,
 				C97699462A540D4200187038 /* CBookmarkViewController.m in Sources */,
 				C9E3611A2A5273BC004D31BE /* CSamplesFuctionViewController.m in Sources */,
+				C97699912A581BA900187038 /* CWatermarkViewController.m in Sources */,
 				C976998D2A580D0400187038 /* CDocumentInfoViewController.m in Sources */,
 				C97699852A57E56900187038 /* CImageExtractViewController.m in Sources */,
 				C97699612A5534D500187038 /* XMLReader.m in Sources */,
 				C9E361142A5273BC004D31BE /* AppDelegate.m in Sources */,
 				C976997D2A56AD3B00187038 /* CInteractiveFormsViewController.m in Sources */,
 				C97699792A569C9400187038 /* CAnnotationImportExportViewController.m in Sources */,
+				C976999C2A5ACAAB00187038 /* CHeaderFooterViewController.m in Sources */,
+				C97699982A5AAEF900187038 /* CBackgroundViewController.m in Sources */,
 				C9E361252A5273BF004D31BE /* main.m in Sources */,
 				C97699892A5800A100187038 /* CTextExtractViewController.m in Sources */,
 				C97699652A554F4800187038 /* CPDFToImageViewController.m in Sources */,

+ 22 - 0
Samples/Samples/Background/CBackgroundViewController.h

@@ -0,0 +1,22 @@
+//
+//  CBackgroundViewController.h
+//  Samples
+//
+//  Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+//
+//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+//  This notice may not be removed from this file.
+//
+
+
+#import "CSamplesBaseViewController.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface CBackgroundViewController : CSamplesBaseViewController
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 298 - 0
Samples/Samples/Background/CBackgroundViewController.m

@@ -0,0 +1,298 @@
+//
+//  CBackgroundViewController.m
+//  Samples
+//
+//  Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+//
+//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+//  This notice may not be removed from this file.
+//
+
+#import "CBackgroundViewController.h"
+
+#import <ComPDFKit/ComPDFKit.h>
+
+//-----------------------------------------------------------------------------------------
+// The sample code illustrates how to add and remove background, including text
+// and image background. date using API.
+//-----------------------------------------------------------------------------------------
+
+@interface CBackgroundViewController ()
+
+@property (nonatomic, strong) CPDFDocument *document;
+
+@property (nonatomic, assign) BOOL isRun;
+
+@property (nonatomic, strong) NSString *commandLineStr;
+
+@property (nonatomic, strong) NSURL *addColorBackgroundURL;
+
+@property (nonatomic, strong) NSURL *addImageBackgroundURL;
+
+@property (nonatomic, strong) NSURL *deleteBackgroundURL;
+
+@end
+
+@implementation CBackgroundViewController
+
+#pragma mark - UIViewController Methods
+
+- (void)viewDidLoad {
+    [super viewDidLoad];
+    // Do any additional setup after loading the view.
+    self.explainLabel.text = NSLocalizedString(@"The sample code illustrates how to add and remove background, including text and image background. date using API.", nil);
+    
+    self.commandLineTextView.text = @"";
+    self.isRun = NO;
+    self.commandLineStr = @"";
+}
+
+#pragma mark - Samples Methods
+
+- (void)addColorBackground:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 1 : Set the document background color\n"];
+    
+    // Save a document in Sandbox
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"Background"];
+    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"Samples",@"CommonFivePage"];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"AddColorBackgroundTest"];
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
+        [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
+    
+    self.addColorBackgroundURL = [NSURL fileURLWithPath:writeFilePath];
+    document = [[CPDFDocument alloc] initWithURL:self.addColorBackgroundURL];
+    
+    CPDFBackground *background = document.background;
+    background.type = CPDFBackgroundTypeColor;
+    background.color = [CPDFKitPlatformColor redColor]; // Background color (image background does not work).
+    background.opacity = 1.0; // Background transparency, the range of 0~1, with the default of 1.
+    background.scale = 1.0; // Background tiling scale.
+    background.rotation = 0; // Background rotation angle, the range of 0~360, the default is 0 (rotate at the centre of the page).
+    background.horizontalAlignment = 1; // Background vertical alignment. `0` for top alignment, `1` for centre alignment, `1` for bottom alignment.
+    background.verticalAlignment = 1; // Horizontal alignment of the background. `0` for left alignment, `1` for centre alignment, `1` for right alignment.
+    background.xOffset = 0; // The horizontal offset of the background. Positive numbers are shifted to the right, negative numbers are shifted to the left.
+    background.yOffset = 0; // The vertical offset of the background. Positive numbers are shifted downwards, negative numbers are shifted upwards.
+
+    background.pageString = @"0,1,2,3,4"; // Background page range, such as "0,3,5-7".
+
+    [background update];
+    
+    [document writeToURL:self.addColorBackgroundURL];
+    
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Type : Color"];
+    CGFloat red, green, blue, alpha;
+    [background.color getRed:&red green:&green blue:&blue alpha:&alpha];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Color : red:%f, green:%f, blue:%f, alpha:%f", red, green, blue, alpha];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Opacity :%f", background.opacity];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Rotation :%f", background.rotation];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Vertalign :%@", [self getStringFromEnumVertalign:background.verticalAlignment]];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Horizalign :%@", [self getStringFromEnumHorizalign:background.horizontalAlignment]];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"VertOffset :%f", background.xOffset];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"HorizOffset :%f", background.yOffset];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Pages :%@", background.pageString];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in AddColorBackgroundTest.pdf\n"];
+}
+
+- (void)addImageBackground:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 2 : Set the document background image\n"];
+    
+    // Save a document in Sandbox
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"Background"];
+    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"Samples",@"CommonFivePage"];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"AddImageBackgroundTest"];
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
+        [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
+    
+    self.addImageBackgroundURL = [NSURL fileURLWithPath:writeFilePath];
+    document = [[CPDFDocument alloc] initWithURL:self.addImageBackgroundURL];
+    
+    CPDFBackground *background = document.background;
+    background.type = CPDFBackgroundTypeImage;
+    [background setImage:[UIImage imageNamed:@"Logo"]];
+    background.opacity = 1.0; // Background transparency, the range of 0~1, with the default of 1.
+    background.scale = 1.0; // Background tiling scale.
+    background.rotation = 0; // Background rotation angle, the range of 0~360, the default is 0 (rotate at the centre of the page).
+    background.horizontalAlignment = 1; // Background vertical alignment. `0` for top alignment, `1` for centre alignment, `1` for bottom alignment.
+    background.verticalAlignment = 1; // Horizontal alignment of the background. `0` for left alignment, `1` for centre alignment, `1` for right alignment.
+    background.xOffset = 0; // The horizontal offset of the background. Positive numbers are shifted to the right, negative numbers are shifted to the left.
+    background.yOffset = 0; // The vertical offset of the background. Positive numbers are shifted downwards, negative numbers are shifted upwards.
+
+    background.pageString = @"0,1,2,3,4"; // Background page range, such as "0,3,5-7".
+
+    [background update];
+    
+    [document writeToURL:self.addImageBackgroundURL];
+    
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Type : Image"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Opacity :%f", background.opacity];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Rotation :%f", background.rotation];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Vertalign :%@", [self getStringFromEnumVertalign:background.verticalAlignment]];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Horizalign :%@", [self getStringFromEnumHorizalign:background.horizontalAlignment]];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"VertOffset :%f", background.xOffset];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"HorizOffset :%f", background.yOffset];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Pages :%@", background.pageString];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in AddImageBackgroundTest.pdf\n"];
+}
+
+- (void)deleteColorBackground:(CPDFDocument *)document {
+//    DeleteBackgroundTest
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 3 :  Delete document background\n"];
+    
+    // Save a document in Sandbox
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"Background"];
+    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"Background",@"AddColorBackgroundTest"];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"DeleteBackgroundTest"];
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
+        [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
+    
+    self.deleteBackgroundURL = [NSURL fileURLWithPath:writeFilePath];
+    document = [[CPDFDocument alloc] initWithURL:self.deleteBackgroundURL];
+    
+    CPDFBackground *pageBackground = [document background];
+    
+    [pageBackground clear];
+    
+    [document writeToURL:self.deleteBackgroundURL];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in AddImageBackgroundTest.pdf\n"];
+}
+
+- (NSString *)getStringFromEnumVertalign:(NSInteger)enums {
+    switch (enums) {
+        case 0:
+            return @"top alignment";
+            break;
+        case 1:
+            return @"center alignment";
+            break;
+        case 2:
+            return @"button alignment";
+            break;
+        default:
+            return @" ";
+            break;
+    }
+}
+
+- (NSString *)getStringFromEnumHorizalign:(NSInteger)enums {
+    switch (enums) {
+        case 0:
+            return @"left alignment";
+            break;
+        case 1:
+            return @"center alignment";
+            break;
+        case 2:
+            return @"right alignment";
+            break;
+        default:
+            return @" ";
+            break;
+    }
+}
+
+- (void)openFileWithURL:(NSURL *)url {
+    UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:@[url] applicationActivities:nil];
+        activityVC.definesPresentationContext = YES;
+    if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
+        activityVC.popoverPresentationController.sourceView = self.openfileButton;
+        activityVC.popoverPresentationController.sourceRect = self.openfileButton.bounds;
+    }
+    [self presentViewController:activityVC animated:YES completion:nil];
+    activityVC.completionWithItemsHandler = ^(UIActivityType  _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
+
+        if (completed) {
+            NSLog(@"Success!");
+        } else {
+            NSLog(@"Failed Or Canceled!");
+        }
+    };
+}
+
+#pragma mark - Action
+
+- (IBAction)buttonItemClick_openFile:(id)sender {
+    // Determine whether to export the document
+    if (self.isRun) {
+        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Choose a file to open...", nil) message:@"" preferredStyle:UIAlertControllerStyleAlert];
+        if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
+            alertController.popoverPresentationController.sourceView = self.openfileButton;
+            alertController.popoverPresentationController.sourceRect = self.openfileButton.bounds;
+        }
+        
+        UIAlertAction *colorBackgroundAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   AddColorBackgroundTest.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.addColorBackgroundURL];
+        }];
+        UIAlertAction *imageBackgroundAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   AddImageBackgroundTest.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.addImageBackgroundURL];
+        }];
+        UIAlertAction *deleteBackgroundAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   DeleteBackgroundTest.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.deleteBackgroundURL];
+        }];
+        
+        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];
+        
+        [alertController addAction:colorBackgroundAction];
+        [alertController addAction:imageBackgroundAction];
+        [alertController addAction:deleteBackgroundAction];
+        [alertController addAction:cancelAction];
+        
+        [self presentViewController:alertController animated:NO completion:nil];
+    } else {
+        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Choose a file to open...", nil) message:@"" preferredStyle:UIAlertControllerStyleAlert];
+        if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
+            alertController.popoverPresentationController.sourceView = self.openfileButton;
+            alertController.popoverPresentationController.sourceRect = self.openfileButton.bounds;
+        }
+        
+        UIAlertAction *noAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"No files for this sample.", nil) style:UIAlertActionStyleDefault handler:nil];
+        
+        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];
+        
+        [alertController addAction:noAction];
+        [alertController addAction:cancelAction];
+        
+        [self presentViewController:alertController animated:NO completion:nil];
+    }
+}
+
+- (IBAction)buttonItemClick_run:(id)sender {
+    self.isRun = YES;
+    
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Running Watermark sample...\n\n"];
+    [self addColorBackground:self.document];
+    [self addImageBackground:self.document];
+    [self deleteColorBackground:self.document];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"\nDone!\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    
+    // Refresh commandline message
+    self.commandLineTextView.text = self.commandLineStr;
+}
+
+@end

+ 21 - 0
Samples/Samples/CSamplesFuctionViewController.m

@@ -23,6 +23,9 @@
 #import "CImageExtractViewController.h"
 #import "CTextExtractViewController.h"
 #import "CDocumentInfoViewController.h"
+#import "CWatermarkViewController.h"
+#import "CBackgroundViewController.h"
+#import "CHeaderFooterViewController.h"
 
 #import <ComPDFKit/ComPDFKit.h>
 
@@ -195,6 +198,24 @@
             [self.navigationController pushViewController:documentInfoVC animated:YES];
         }
             break;
+        case CSamplesTypeWatermark:
+        {
+            CWatermarkViewController *watermarkVC = [[CWatermarkViewController alloc] initWithDocument:self.document];
+            [self.navigationController pushViewController:watermarkVC animated:YES];
+        }
+            break;
+        case CSamplesTypeBackground:
+        {
+            CBackgroundViewController *backgroundVC = [[CBackgroundViewController alloc] initWithDocument:self.document];
+            [self.navigationController pushViewController:backgroundVC animated:YES];
+        }
+            break;
+        case CSamplesTypeHeaderFooter:
+        {
+            CHeaderFooterViewController *headerfooterVC = [[CHeaderFooterViewController alloc] initWithDocument:self.document];
+            [self.navigationController pushViewController:headerfooterVC animated:YES];
+        }
+            break;
             
         default:
             break;

+ 22 - 0
Samples/Samples/HeaderFooter/CHeaderFooterViewController.h

@@ -0,0 +1,22 @@
+//
+//  CHeaderFooterViewController.h
+//  Samples
+//
+//  Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+//
+//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+//  This notice may not be removed from this file.
+//
+
+
+#import "CSamplesBaseViewController.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface CHeaderFooterViewController : CSamplesBaseViewController
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 319 - 0
Samples/Samples/HeaderFooter/CHeaderFooterViewController.m

@@ -0,0 +1,319 @@
+//
+//  CHeaderFooterViewController.m
+//  Samples
+//
+//  Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+//
+//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+//  This notice may not be removed from this file.
+//
+
+
+#import "CHeaderFooterViewController.h"
+
+#import <ComPDFKit/ComPDFKit.h>
+
+//-----------------------------------------------------------------------------------------
+// The sample code illustrates how to add and remove header footer susing API.
+//-----------------------------------------------------------------------------------------
+
+@interface CHeaderFooterViewController ()
+
+@property (nonatomic, strong) CPDFDocument *document;
+
+@property (nonatomic, assign) BOOL isRun;
+
+@property (nonatomic, strong) NSString *commandLineStr;
+
+@property (nonatomic, strong) NSURL *addCommonHeaderFooterURL;
+
+@property (nonatomic, strong) NSURL *addPageHeaderFooterURL;
+
+@property (nonatomic, strong) NSURL *editHeaderFooterURL;
+
+@property (nonatomic, strong) NSURL *deleteHeaderFooterURL;
+
+@end
+
+@implementation CHeaderFooterViewController
+
+#pragma mark - UIViewController Methods
+
+- (void)viewDidLoad {
+    [super viewDidLoad];
+    // Do any additional setup after loading the view.
+    self.explainLabel.text = NSLocalizedString(@"The sample code illustrates how to add and remove header footer using API.", nil);
+    
+    self.commandLineTextView.text = @"";
+    self.isRun = NO;
+    self.commandLineStr = @"";
+}
+
+#pragma mark - Samples Methods
+
+- (void)addCommonHeaderFooter:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 1: Insert common header footer\n"];
+    
+    // Save a document in Sandbox
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"HeaderFoooter"];
+    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"Samples",@"CommonFivePage"];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"AddCommonHeaderFooterTest"];
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
+        [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
+    
+    self.addCommonHeaderFooterURL = [NSURL fileURLWithPath:writeFilePath];
+    document = [[CPDFDocument alloc] initWithURL:self.addCommonHeaderFooterURL];
+    
+    CPDFHeaderFooter *headerFooter = document.headerFooter;
+    [headerFooter setText:@"ComPDFKit" atIndex:0];
+    [headerFooter setText:@"ComPDFKit" atIndex:1];
+    [headerFooter setText:@"ComPDFKit" atIndex:2];
+    [headerFooter setTextColor:[CPDFKitPlatformColor redColor] atIndex:0];
+    [headerFooter setFontSize:14.0 atIndex:0];
+    [headerFooter setTextColor:[CPDFKitPlatformColor redColor] atIndex:1];
+    [headerFooter setFontSize:14.0 atIndex:1];
+    [headerFooter setTextColor:[CPDFKitPlatformColor redColor] atIndex:2];
+    [headerFooter setFontSize:14.0 atIndex:2];
+    headerFooter.pageString = @"0-4";
+    
+    [headerFooter update];
+    
+    for (int i = 0; i < 3; i++) {
+        self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Text: %@\n", [headerFooter textAtIndex:i]];
+        self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Location: %@\n\n", [self getStringFromEnumLocation:i]];
+    }
+    
+    [document writeToURL:self.addCommonHeaderFooterURL];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in AddCommonHeaderFooterTest.pdf\n"];
+}
+
+- (void)addPageHeaderFooter:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 2: Insert page header footer\n"];
+    
+    // Save a document in Sandbox
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"HeaderFoooter"];
+    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"Samples",@"CommonFivePage"];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"AddPageHeaderFooterTest"];
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
+        [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
+    
+    self.addPageHeaderFooterURL = [NSURL fileURLWithPath:writeFilePath];
+    document = [[CPDFDocument alloc] initWithURL:self.addPageHeaderFooterURL];
+    
+    CPDFHeaderFooter *headerFooter = document.headerFooter;
+    [headerFooter setText:@"<<1,2>>" atIndex:0];
+    [headerFooter setText:@"<<1,2>>" atIndex:1];
+    [headerFooter setText:@"<<1,2>>" atIndex:2];
+    [headerFooter setTextColor:[CPDFKitPlatformColor redColor] atIndex:0];
+    [headerFooter setFontSize:14.0 atIndex:0];
+    [headerFooter setTextColor:[CPDFKitPlatformColor redColor] atIndex:0];
+    [headerFooter setFontSize:14.0 atIndex:1];
+    [headerFooter setTextColor:[CPDFKitPlatformColor redColor] atIndex:0];
+    [headerFooter setFontSize:14.0 atIndex:2];
+    headerFooter.pageString = @"0-4";
+    
+    [headerFooter update];
+    
+    for (int i = 0; i < 3; i++) {
+        self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Text: %@\n", [headerFooter textAtIndex:i]];
+        self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Location: %@\n\n", [self getStringFromEnumLocation:i]];
+    }
+    
+    [document writeToURL:self.addPageHeaderFooterURL];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in AddPageHeaderFooterTest.pdf\n"];
+}
+
+- (void)editHeaderFooter:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 3: Edit header footer\n"];
+    
+    // Save a document in Sandbox
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"HeaderFoooter"];
+    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"HeaderFoooter",@"AddCommonHeaderFooterTest"];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"EditHeaderFooterTest"];
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
+        [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
+    
+    self.editHeaderFooterURL = [NSURL fileURLWithPath:writeFilePath];
+    document = [[CPDFDocument alloc] initWithURL:self.editHeaderFooterURL];
+    
+    CPDFHeaderFooter *headerFooter = document.headerFooter;
+    [headerFooter setText:@"ComPDFKit Samples" atIndex:0];
+    [headerFooter setText:@"ComPDFKit" atIndex:1];
+    [headerFooter setText:@"ComPDFKit" atIndex:2];
+    [headerFooter update];
+    
+    for (int i = 0; i < 3; i++) {
+        self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Text: %@\n", [headerFooter textAtIndex:i]];
+        self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Location: %@\n\n", [self getStringFromEnumLocation:i]];
+    }
+    
+    [document writeToURL:self.editHeaderFooterURL];
+    
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in EditHeaderFooterTest.pdf\n"];
+}
+
+- (void)deleteHeaderFooter:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 4: Delete header footer\n"];
+    
+    // Save a document in Sandbox
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"HeaderFoooter"];
+    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"HeaderFoooter",@"AddCommonHeaderFooterTest"];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"DeleteHeaderFooterTest"];
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
+        [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
+    
+    self.deleteHeaderFooterURL = [NSURL fileURLWithPath:writeFilePath];
+    document = [[CPDFDocument alloc] initWithURL:self.deleteHeaderFooterURL];
+    
+    CPDFHeaderFooter *headerFooter = document.headerFooter;
+    [headerFooter clear];
+    
+    [document writeToURL:self.deleteHeaderFooterURL];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in DeleteHeaderFooterTest.pdf\n"];
+}
+
+- (NSString *)getStringFromEnumLocation:(NSInteger)enums {
+    switch (enums) {
+        case 0:
+            return @"Top Left";
+            break;
+        case 1:
+            return @"Top Middle";
+            break;
+        case 2:
+            return @"Top Right";
+            break;
+        case 3:
+            return @"Button Left";
+            break;
+        case 4:
+            return @"Button Middle";
+            break;
+        case 5:
+            return @"Button Right";
+            break;
+        default:
+            return @" ";
+            break;
+    }
+}
+
+
+- (void)openFileWithURL:(NSURL *)url {
+    UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:@[url] applicationActivities:nil];
+        activityVC.definesPresentationContext = YES;
+    if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
+        activityVC.popoverPresentationController.sourceView = self.openfileButton;
+        activityVC.popoverPresentationController.sourceRect = self.openfileButton.bounds;
+    }
+    [self presentViewController:activityVC animated:YES completion:nil];
+    activityVC.completionWithItemsHandler = ^(UIActivityType  _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
+
+        if (completed) {
+            NSLog(@"Success!");
+        } else {
+            NSLog(@"Failed Or Canceled!");
+        }
+    };
+}
+
+#pragma mark - Action
+
+- (IBAction)buttonItemClick_openFile:(id)sender {
+    // Determine whether to export the document
+    if (self.isRun) {
+        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Choose a file to open...", nil) message:@"" preferredStyle:UIAlertControllerStyleAlert];
+        if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
+            alertController.popoverPresentationController.sourceView = self.openfileButton;
+            alertController.popoverPresentationController.sourceRect = self.openfileButton.bounds;
+        }
+        
+        UIAlertAction *commonHeaderFooterAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   AddCommonHeaderFooterTest.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.addCommonHeaderFooterURL];
+        }];
+        UIAlertAction *pageHeaderFooterAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   AddPageHeaderFooterTest.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.addPageHeaderFooterURL];
+        }];
+        UIAlertAction *editHeaderFooterAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   EditHeaderFooterTest.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.editHeaderFooterURL];
+        }];
+        UIAlertAction *deleteHeaderFooterAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   DeleteHeaderFooterTest.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.deleteHeaderFooterURL];
+        }];
+        
+        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];
+        
+        [alertController addAction:commonHeaderFooterAction];
+        [alertController addAction:pageHeaderFooterAction];
+        [alertController addAction:editHeaderFooterAction];
+        [alertController addAction:deleteHeaderFooterAction];
+        [alertController addAction:cancelAction];
+        
+        [self presentViewController:alertController animated:NO completion:nil];
+    } else {
+        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Choose a file to open...", nil) message:@"" preferredStyle:UIAlertControllerStyleAlert];
+        if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
+            alertController.popoverPresentationController.sourceView = self.openfileButton;
+            alertController.popoverPresentationController.sourceRect = self.openfileButton.bounds;
+        }
+        
+        UIAlertAction *noAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"No files for this sample.", nil) style:UIAlertActionStyleDefault handler:nil];
+        
+        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];
+        
+        [alertController addAction:noAction];
+        [alertController addAction:cancelAction];
+        
+        [self presentViewController:alertController animated:NO completion:nil];
+    }
+}
+
+- (IBAction)buttonItemClick_run:(id)sender {
+    self.isRun = YES;
+    
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Running Watermark sample...\n\n"];
+    [self addCommonHeaderFooter:self.document];
+    [self addPageHeaderFooter:self.document];
+    [self editHeaderFooter:self.document];
+    [self deleteHeaderFooter:self.document];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"\nDone!\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    
+    // Refresh commandline message
+    self.commandLineTextView.text = self.commandLineStr;
+}
+@end

+ 0 - 1
Samples/Samples/PDFPage/CPDFPageViewController.m

@@ -301,7 +301,6 @@
     // Save a document in Sandbox
     NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
     NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"PDFPage"];
-    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"Samples",@"CommonFivePage"];
     
     // Copy file
     if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])

+ 22 - 0
Samples/Samples/Watermark/CWatermarkViewController.h

@@ -0,0 +1,22 @@
+//
+//  CWatermarkViewController.h
+//  Samples
+//
+//  Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+//
+//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+//  This notice may not be removed from this file.
+//
+
+
+#import "CSamplesBaseViewController.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface CWatermarkViewController : CSamplesBaseViewController
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 374 - 0
Samples/Samples/Watermark/CWatermarkViewController.m

@@ -0,0 +1,374 @@
+//
+//  CWatermarkViewController.m
+//  Samples
+//
+//  Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+//
+//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+//  This notice may not be removed from this file.
+//
+
+
+#import "CWatermarkViewController.h"
+
+#import <ComPDFKit/ComPDFKit.h>
+
+//-----------------------------------------------------------------------------------------
+// The sample code illustrates how to add and remove watermarks, including text
+// and image watermarks. date using API.
+//-----------------------------------------------------------------------------------------
+
+@interface CWatermarkViewController ()
+
+@property (nonatomic, strong) CPDFDocument *document;
+
+@property (nonatomic, assign) BOOL isRun;
+
+@property (nonatomic, strong) NSString *commandLineStr;
+
+@property (nonatomic, strong) NSURL *addTextWatermarkURL;
+
+@property (nonatomic, strong) NSURL *addTilesWatermarkURL;
+
+@property (nonatomic, strong) NSURL *addImageWatermarkURL;
+
+@property (nonatomic, strong) NSURL *deleteWatermarkURL;
+
+@end
+
+@implementation CWatermarkViewController
+
+#pragma mark - UIViewController Methods
+
+- (void)viewDidLoad {
+    [super viewDidLoad];
+    // Do any additional setup after loading the view.
+    self.explainLabel.text = NSLocalizedString(@"The sample code illustrates how to add and remove watermarks, including text and image watermarks. date using API.", nil);
+    
+    self.commandLineTextView.text = @"";
+    self.isRun = NO;
+    self.commandLineStr = @"";
+}
+
+#pragma mark - Samples Methods
+
+- (void)addTextWatermark:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 1: Insert text watermark\n"];
+    
+    // Save a document in Sandbox
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"Watermark"];
+    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"Samples",@"CommonFivePage"];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"AddTextWatermarkTest"];
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
+        [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
+    
+    self.addTextWatermarkURL = [NSURL fileURLWithPath:writeFilePath];
+    document = [[CPDFDocument alloc] initWithURL:self.addTextWatermarkURL];
+    
+    CPDFWatermark *watermark = [[CPDFWatermark alloc] initWithDocument:document type:CPDFWatermarkTypeText];
+    
+    watermark.text = @"ComPDFKit"; // The text for the watermark (image watermark does not work).
+    watermark.textFont = [UIFont fontWithName:@"Helvetica" size:30]; // The text font for the watermark (image watermark does not work). Default Font : Helvetica 24.
+    watermark.textColor = [UIColor redColor]; // The text color for the watermark (image watermark does not work).
+    watermark.scale = 2.0; // Watermark scaling with default `1`, if it is a picture watermark `1` represents the original size of the picture, if it is a text watermark `1` represents the `textFont` font size.
+
+    watermark.rotation = 45; // Watermark rotation angle, the range of 0~360, with the default of 0.
+    watermark.opacity = 0.5; // Watermark transparency, the range of 0~1, with the default of 1.
+    watermark.verticalPosition = CPDFWatermarkVerticalPositionCenter; // Vertical alignment of the watermark.
+    watermark.horizontalPosition = CPDFWatermarkHorizontalPositionCenter; // Horizontal alignment of the watermark.
+    watermark.tx = 0.0; // The translation relative to the horizontal position. Positive numbers are shifted to the right, negative numbers are shifted to the left.
+    watermark.ty = 0.0; // The translation relative to the vertical position. Positive numbers are shifted downwards, negative numbers are shifted upwards.
+    watermark.isFront = YES; // Set watermark to locate in front of the content.
+    watermark.isTilePage = NO; // Set tiled watermark for the page(image watermark does not work).
+//    watermark.verticalSpacing = 10; // Set the vertical spacing for the tiled watermark.
+//    watermark.horizontalSpacing = 10; // Set the horizontal spacing for the tiled watermark.
+    watermark.pageString = @"0-4";
+    [document addWatermark:watermark];
+    [document updateWatermark:watermark];
+    
+    [document writeToURL:self.addTextWatermarkURL];
+    
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Text :%@", watermark.text];
+    CGFloat red, green, blue, alpha;
+    [watermark.textColor getRed:&red green:&green blue:&blue alpha:&alpha];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Color : red:%f, green:%f, blue:%f, alpha:%f", red, green, blue, alpha];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"FontSize :%f", watermark.textFont.pointSize];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Opacity :%f", watermark.opacity];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Vertalign :%@", [self getStringFromEnumVertalign:watermark.verticalPosition]];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Horizalign :%@", [self getStringFromEnumHorizalign:watermark.horizontalPosition]];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"VertOffset :%f", watermark.tx];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"HorizOffset :%f", watermark.ty];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Pages :%@", watermark.pageString];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"VerticalSpacing :%f", watermark.verticalSpacing];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"HorizontalSpacing :%f", watermark.horizontalSpacing];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in AddTextWatermarkTest.pdf\n"];
+}
+
+- (void)addImageWatermark:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 2: Insert Image Watermark\n"];
+    
+    // Save a document in Sandbox
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"Watermark"];
+    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"Samples",@"CommonFivePage"];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"AddImageWatermarkTest"];
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
+        [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
+    
+    self.addImageWatermarkURL = [NSURL fileURLWithPath:writeFilePath];
+    document = [[CPDFDocument alloc] initWithURL:self.addImageWatermarkURL];
+    
+    CPDFWatermark *watermark = [[CPDFWatermark alloc] initWithDocument:document type:CPDFWatermarkTypeImage];
+    
+    watermark.image = [UIImage imageNamed:@"Logo"];
+    watermark.scale = 2.0; // Watermark scaling with default `1`, if it is a picture watermark `1` represents the original size of the picture, if it is a text watermark `1` represents the `textFont` font size.
+
+    watermark.rotation = 45; // Watermark rotation angle, the range of 0~360, with the default of 0.
+    watermark.opacity = 0.5; // Watermark transparency, the range of 0~1, with the default of 1.
+    watermark.verticalPosition = CPDFWatermarkVerticalPositionCenter; // Vertical alignment of the watermark.
+    watermark.horizontalPosition = CPDFWatermarkHorizontalPositionCenter; // Horizontal alignment of the watermark.
+    watermark.tx = 0.0; // The translation relative to the horizontal position. Positive numbers are shifted to the right, negative numbers are shifted to the left.
+    watermark.ty = 0.0; // The translation relative to the vertical position. Positive numbers are shifted downwards, negative numbers are shifted upwards.
+    watermark.isFront = YES; // Set watermark to locate in front of the content.
+//    watermark.verticalSpacing = 10; // Set the vertical spacing for the tiled watermark.
+//    watermark.horizontalSpacing = 10; // Set the horizontal spacing for the tiled watermark.
+    watermark.pageString = @"0-4";
+    [document addWatermark:watermark];
+//    [document updateWatermark:watermark];
+    
+    [document writeToURL:self.addImageWatermarkURL];
+    
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Opacity :%f", watermark.opacity];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Vertalign :%@", [self getStringFromEnumVertalign:watermark.verticalPosition]];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Horizalign :%@", [self getStringFromEnumHorizalign:watermark.horizontalPosition]];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"VertOffset :%f", watermark.tx];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"HorizOffset :%f", watermark.ty];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Pages :%@", watermark.pageString];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"VerticalSpacing :%f", watermark.verticalSpacing];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"HorizontalSpacing :%f", watermark.horizontalSpacing];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in AddImageWatermarkTest.pdf\n"];
+}
+
+- (void)addTilesWatermark:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 3: Insert Text Tiles Watermark\n"];
+    
+    // Save a document in Sandbox
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"Watermark"];
+    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"Samples",@"CommonFivePage"];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"AddTilesWatermarkTest"];
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
+        [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
+    
+    self.addTilesWatermarkURL = [NSURL fileURLWithPath:writeFilePath];
+    document = [[CPDFDocument alloc] initWithURL:self.addTilesWatermarkURL];
+    
+    CPDFWatermark *watermark = [[CPDFWatermark alloc] initWithDocument:document type:CPDFWatermarkTypeText];
+    
+    watermark.text = @"ComPDFKit"; // The text for the watermark (image watermark does not work).
+    watermark.textFont = [UIFont fontWithName:@"Helvetica" size:30]; // The text font for the watermark (image watermark does not work). Default Font : Helvetica 24.
+    watermark.textColor = [UIColor redColor]; // The text color for the watermark (image watermark does not work).
+    watermark.scale = 2.0; // Watermark scaling with default `1`, if it is a picture watermark `1` represents the original size of the picture, if it is a text watermark `1` represents the `textFont` font size.
+
+    watermark.rotation = 45; // Watermark rotation angle, the range of 0~360, with the default of 0.
+    watermark.opacity = 0.5; // Watermark transparency, the range of 0~1, with the default of 1.
+    watermark.verticalPosition = CPDFWatermarkVerticalPositionCenter; // Vertical alignment of the watermark.
+    watermark.horizontalPosition = CPDFWatermarkHorizontalPositionCenter; // Horizontal alignment of the watermark.
+    watermark.tx = 0.0; // The translation relative to the horizontal position. Positive numbers are shifted to the right, negative numbers are shifted to the left.
+    watermark.ty = 0.0; // The translation relative to the vertical position. Positive numbers are shifted downwards, negative numbers are shifted upwards.
+    watermark.isFront = YES; // Set watermark to locate in front of the content.
+    watermark.isTilePage = YES; // Set tiled watermark for the page(image watermark does not work).
+    watermark.verticalSpacing = 10; // Set the vertical spacing for the tiled watermark.
+    watermark.horizontalSpacing = 10; // Set the horizontal spacing for the tiled watermark.
+    watermark.pageString = @"0-4";
+    [document addWatermark:watermark];
+//    [document updateWatermark:watermark];
+    
+    [document writeToURL:self.addTilesWatermarkURL];
+    
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Text :%@", watermark.text];
+    CGFloat red, green, blue, alpha;
+    [watermark.textColor getRed:&red green:&green blue:&blue alpha:&alpha];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Color : red:%f, green:%f, blue:%f, alpha:%f", red, green, blue, alpha];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"FontSize :%f", watermark.textFont.pointSize];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Opacity :%f", watermark.opacity];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Vertalign :%@", [self getStringFromEnumVertalign:watermark.verticalPosition]];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Horizalign :%@", [self getStringFromEnumHorizalign:watermark.horizontalPosition]];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"VertOffset :%f", watermark.tx];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"HorizOffset :%f", watermark.ty];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Pages :%@", watermark.pageString];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"VerticalSpacing :%f", watermark.verticalSpacing];
+    self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"HorizontalSpacing :%f", watermark.horizontalSpacing];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in AddTilesWatermarkTest.pdf\n"];
+}
+
+- (void)deletetWatermark:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 4:Delete Watermark\n"];
+    
+    // Save a document in Sandbox
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"Watermark"];
+    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"Watermark",@"AddTextWatermarkTest"];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"DeleteWatermarkTest"];
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
+        [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
+    self.deleteWatermarkURL = [NSURL fileURLWithPath:writeFilePath];
+    document = [[CPDFDocument alloc] initWithURL:self.deleteWatermarkURL];
+    
+    NSArray *waterArray = [document watermarks];
+    [document removeWatermark:waterArray[0]];
+    
+    [document writeToURL:self.deleteWatermarkURL];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in DeleteWatermarkTest.pdf\n"];
+}
+
+- (NSString *)getStringFromEnumVertalign:(NSInteger)enums {
+    switch (enums) {
+        case 0:
+            return @"CPDFWatermarkVerticalPositionTop";
+            break;
+        case 1:
+            return @"WATERMARK_VERTALIGN_CENTER";
+            break;
+        case 2:
+            return @"CPDFWatermarkVerticalPositionBottom";
+            break;
+        default:
+            return @" ";
+            break;
+    }
+}
+
+- (NSString *)getStringFromEnumHorizalign:(NSInteger)enums {
+    switch (enums) {
+        case 0:
+            return @"CPDFWatermarkHorizontalPositionLeft";
+            break;
+        case 1:
+            return @"CPDFWatermarkHorizontalPositionCenter";
+            break;
+        case 2:
+            return @"CPDFWatermarkHorizontalPositionRight";
+            break;
+        default:
+            return @" ";
+            break;
+    }
+}
+
+- (void)openFileWithURL:(NSURL *)url {
+    UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:@[url] applicationActivities:nil];
+        activityVC.definesPresentationContext = YES;
+    if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
+        activityVC.popoverPresentationController.sourceView = self.openfileButton;
+        activityVC.popoverPresentationController.sourceRect = self.openfileButton.bounds;
+    }
+    [self presentViewController:activityVC animated:YES completion:nil];
+    activityVC.completionWithItemsHandler = ^(UIActivityType  _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
+
+        if (completed) {
+            NSLog(@"Success!");
+        } else {
+            NSLog(@"Failed Or Canceled!");
+        }
+    };
+}
+
+#pragma mark - Action
+
+- (IBAction)buttonItemClick_openFile:(id)sender {
+    // Determine whether to export the document
+    if (self.isRun) {
+        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Choose a file to open...", nil) message:@"" preferredStyle:UIAlertControllerStyleAlert];
+        if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
+            alertController.popoverPresentationController.sourceView = self.openfileButton;
+            alertController.popoverPresentationController.sourceRect = self.openfileButton.bounds;
+        }
+        
+        UIAlertAction *textWatermarkAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   AddTextWatermarkTest.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.addTextWatermarkURL];
+        }];
+        UIAlertAction *imageWatermarkAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   AddImageWatermarkTest.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.addImageWatermarkURL];
+        }];
+        UIAlertAction *tilesWatermarkAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   AddTilesWatermarkTest.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.addTilesWatermarkURL];
+        }];
+        UIAlertAction *deleteWatermarkAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   DeleteWatermarkTest.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.deleteWatermarkURL];
+        }];
+        
+        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];
+        
+        [alertController addAction:textWatermarkAction];
+        [alertController addAction:imageWatermarkAction];
+        [alertController addAction:tilesWatermarkAction];
+        [alertController addAction:deleteWatermarkAction];
+        [alertController addAction:cancelAction];
+        
+        [self presentViewController:alertController animated:NO completion:nil];
+    } else {
+        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Choose a file to open...", nil) message:@"" preferredStyle:UIAlertControllerStyleAlert];
+        if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
+            alertController.popoverPresentationController.sourceView = self.openfileButton;
+            alertController.popoverPresentationController.sourceRect = self.openfileButton.bounds;
+        }
+        
+        UIAlertAction *noAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"No files for this sample.", nil) style:UIAlertActionStyleDefault handler:nil];
+        
+        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];
+        
+        [alertController addAction:noAction];
+        [alertController addAction:cancelAction];
+        
+        [self presentViewController:alertController animated:NO completion:nil];
+    }
+}
+
+- (IBAction)buttonItemClick_run:(id)sender {
+    self.isRun = YES;
+    
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Running Watermark sample...\n\n"];
+    [self addTextWatermark:self.document];
+    [self addImageWatermark:self.document];
+    [self addTilesWatermark:self.document];
+    [self deletetWatermark:self.document];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"\nDone!\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    
+    // Refresh commandline message
+    self.commandLineTextView.text = self.commandLineStr;
+}
+
+@end

BIN
TestFile/Logo.png