CWatermarkViewController.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. //
  2. // CWatermarkViewController.m
  3. // Samples
  4. //
  5. // Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. #import "CWatermarkViewController.h"
  13. #import <ComPDFKit/ComPDFKit.h>
  14. //-----------------------------------------------------------------------------------------
  15. // The sample code illustrates how to add and remove watermarks, including text
  16. // and image watermarks. date using API.
  17. //-----------------------------------------------------------------------------------------
  18. @interface CWatermarkViewController ()
  19. @property (nonatomic, strong) CPDFDocument *document;
  20. @property (nonatomic, assign) BOOL isRun;
  21. @property (nonatomic, strong) NSString *commandLineStr;
  22. @property (nonatomic, strong) NSURL *addTextWatermarkURL;
  23. @property (nonatomic, strong) NSURL *addTilesWatermarkURL;
  24. @property (nonatomic, strong) NSURL *addImageWatermarkURL;
  25. @property (nonatomic, strong) NSURL *deleteWatermarkURL;
  26. @end
  27. @implementation CWatermarkViewController
  28. #pragma mark - UIViewController Methods
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. // Do any additional setup after loading the view.
  32. self.explainLabel.text = NSLocalizedString(@"This sample shows how to add watermarks, including text, image and tile watermarks, and delete watermarks.", nil);
  33. self.commandLineTextView.text = @"";
  34. self.isRun = NO;
  35. self.commandLineStr = @"";
  36. }
  37. #pragma mark - Samples Methods
  38. - (void)addTextWatermark:(CPDFDocument *)document {
  39. self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
  40. self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 1: Insert text watermark\n"];
  41. // Get Sandbox path for saving the PDFFile
  42. NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
  43. NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"Watermark"];
  44. if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
  45. [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
  46. NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"AddTextWatermarkTest"];
  47. // Save the document in the test PDF file
  48. self.addTextWatermarkURL = [NSURL fileURLWithPath:writeFilePath];
  49. [document writeToURL:self.addTextWatermarkURL];
  50. // Create a new document for test PDF file
  51. document = [[CPDFDocument alloc] initWithURL:self.addTextWatermarkURL];
  52. // Create text watermark
  53. CPDFWatermark *watermark = [[CPDFWatermark alloc] initWithDocument:document type:CPDFWatermarkTypeText];
  54. watermark.text = @"ComPDFKit"; // The text for the watermark (image watermark does not work).
  55. watermark.textFont = [UIFont fontWithName:@"Helvetica" size:30]; // The text font for the watermark (image watermark does not work). Default Font : Helvetica 24.
  56. watermark.textColor = [UIColor redColor]; // The text color for the watermark (image watermark does not work).
  57. 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.
  58. watermark.rotation = 45; // Watermark rotation angle, the range of 0~360, with the default of 0.
  59. watermark.opacity = 0.5; // Watermark transparency, the range of 0~1, with the default of 1.
  60. watermark.verticalPosition = CPDFWatermarkVerticalPositionCenter; // Vertical alignment of the watermark.
  61. watermark.horizontalPosition = CPDFWatermarkHorizontalPositionCenter; // Horizontal alignment of the watermark.
  62. 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.
  63. watermark.ty = 0.0; // The translation relative to the vertical position. Positive numbers are shifted downwards, negative numbers are shifted upwards.
  64. watermark.isFront = YES; // Set watermark to locate in front of the content.
  65. watermark.isTilePage = NO; // Set tiled watermark for the page(image watermark does not work).
  66. watermark.pageString = @"0-4";
  67. [document addWatermark:watermark];
  68. [document updateWatermark:watermark];
  69. [document writeToURL:self.addTextWatermarkURL];
  70. // Print text watermark object message
  71. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Text :%@", watermark.text];
  72. CGFloat red, green, blue, alpha;
  73. [watermark.textColor getRed:&red green:&green blue:&blue alpha:&alpha];
  74. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Color : red:%.1f, green:%.1f, blue:%.1f, alpha:%.1f\n", red, green, blue, alpha];
  75. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"FontSize :%.1f\n", watermark.textFont.pointSize];
  76. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Opacity :%.1f\n", watermark.opacity];
  77. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Vertalign :%@\n", [self getStringFromEnumVertalign:watermark.verticalPosition]];
  78. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Horizalign :%@\n", [self getStringFromEnumHorizalign:watermark.horizontalPosition]];
  79. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"VertOffset :%.1f\n", watermark.tx];
  80. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"HorizOffset :%.1f\n", watermark.ty];
  81. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Pages :%@\n", watermark.pageString];
  82. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"VerticalSpacing :%.1f\n", watermark.verticalSpacing];
  83. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"HorizontalSpacing :%.1f\n", watermark.horizontalSpacing];
  84. self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in AddTextWatermarkTest.pdf\n"];
  85. }
  86. - (void)addImageWatermark:(CPDFDocument *)document {
  87. self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
  88. self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 2: Insert Image Watermark\n"];
  89. // Get Sandbox path for saving the PDFFile
  90. NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
  91. NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"Watermark"];
  92. if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
  93. [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
  94. NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"AddImageWatermarkTest"];
  95. // Save the document in the test PDF file
  96. self.addImageWatermarkURL = [NSURL fileURLWithPath:writeFilePath];
  97. [document writeToURL:self.addImageWatermarkURL];
  98. // Create a new document for test PDF file
  99. document = [[CPDFDocument alloc] initWithURL:self.addImageWatermarkURL];
  100. // Create a image watermark
  101. CPDFWatermark *watermark = [[CPDFWatermark alloc] initWithDocument:document type:CPDFWatermarkTypeImage];
  102. watermark.image = [UIImage imageNamed:@"Logo"];
  103. 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.
  104. watermark.rotation = 45; // Watermark rotation angle, the range of 0~360, with the default of 0.
  105. watermark.opacity = 0.5; // Watermark transparency, the range of 0~1, with the default of 1.
  106. watermark.verticalPosition = CPDFWatermarkVerticalPositionCenter; // Vertical alignment of the watermark.
  107. watermark.horizontalPosition = CPDFWatermarkHorizontalPositionCenter; // Horizontal alignment of the watermark.
  108. 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.
  109. watermark.ty = 0.0; // The translation relative to the vertical position. Positive numbers are shifted downwards, negative numbers are shifted upwards.
  110. watermark.isFront = YES; // Set watermark to locate in front of the content.
  111. watermark.pageString = @"0-4";
  112. [document addWatermark:watermark];
  113. [document writeToURL:self.addImageWatermarkURL];
  114. // Print text watermark object message
  115. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Opacity :%.1f\n", watermark.opacity];
  116. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Vertalign :%@\n", [self getStringFromEnumVertalign:watermark.verticalPosition]];
  117. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Horizalign :%@\n", [self getStringFromEnumHorizalign:watermark.horizontalPosition]];
  118. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"VertOffset :%.1f\n", watermark.tx];
  119. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"HorizOffset :%.1f\n", watermark.ty];
  120. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Pages :%@\n", watermark.pageString];
  121. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"VerticalSpacing :%.1f\n", watermark.verticalSpacing];
  122. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"HorizontalSpacing :%.1f\n", watermark.horizontalSpacing];
  123. self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in AddImageWatermarkTest.pdf\n"];
  124. }
  125. - (void)addTilesWatermark:(CPDFDocument *)document {
  126. self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
  127. self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 3: Insert Text Tiles Watermark\n"];
  128. // Get Sandbox path for saving the PDFFile
  129. NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
  130. NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"Watermark"];
  131. if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
  132. [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
  133. NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"AddTilesWatermarkTest"];
  134. // Save the document in the test PDF file
  135. self.addTilesWatermarkURL = [NSURL fileURLWithPath:writeFilePath];
  136. [document writeToURL:self.addTilesWatermarkURL];
  137. // Create a new document for test PDF file
  138. document = [[CPDFDocument alloc] initWithURL:self.addTilesWatermarkURL];
  139. // Create text tiles watermark
  140. CPDFWatermark *watermark = [[CPDFWatermark alloc] initWithDocument:document type:CPDFWatermarkTypeText];
  141. watermark.text = @"ComPDFKit"; // The text for the watermark (image watermark does not work).
  142. watermark.textFont = [UIFont fontWithName:@"Helvetica" size:30]; // The text font for the watermark (image watermark does not work). Default Font : Helvetica 24.
  143. watermark.textColor = [UIColor redColor]; // The text color for the watermark (image watermark does not work).
  144. 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.
  145. watermark.rotation = 45; // Watermark rotation angle, the range of 0~360, with the default of 0.
  146. watermark.opacity = 0.5; // Watermark transparency, the range of 0~1, with the default of 1.
  147. watermark.verticalPosition = CPDFWatermarkVerticalPositionCenter; // Vertical alignment of the watermark.
  148. watermark.horizontalPosition = CPDFWatermarkHorizontalPositionCenter; // Horizontal alignment of the watermark.
  149. 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.
  150. watermark.ty = 0.0; // The translation relative to the vertical position. Positive numbers are shifted downwards, negative numbers are shifted upwards.
  151. watermark.isFront = YES; // Set watermark to locate in front of the content.
  152. watermark.isTilePage = YES; // Set tiled watermark for the page(image watermark does not work).
  153. watermark.verticalSpacing = 10; // Set the vertical spacing for the tiled watermark.
  154. watermark.horizontalSpacing = 10; // Set the horizontal spacing for the tiled watermark.
  155. watermark.pageString = @"0-4";
  156. [document addWatermark:watermark];
  157. [document writeToURL:self.addTilesWatermarkURL];
  158. // Print text tiles watermark message
  159. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Text :%@\n", watermark.text];
  160. CGFloat red, green, blue, alpha;
  161. [watermark.textColor getRed:&red green:&green blue:&blue alpha:&alpha];
  162. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Color : red:%.1f, green:%.1f, blue:%f, alpha:%.1f\n", red, green, blue, alpha];
  163. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"FontSize :%.1f\n", watermark.textFont.pointSize];
  164. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Opacity :%.1f\n", watermark.opacity];
  165. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Vertalign :%@\n", [self getStringFromEnumVertalign:watermark.verticalPosition]];
  166. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Horizalign :%@\n", [self getStringFromEnumHorizalign:watermark.horizontalPosition]];
  167. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"VertOffset :%.1f\n", watermark.tx];
  168. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"HorizOffset :%.1f\n", watermark.ty];
  169. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Pages :%@\n", watermark.pageString];
  170. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"VerticalSpacing :%.1f\n", watermark.verticalSpacing];
  171. self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"HorizontalSpacing :%.1f\n", watermark.horizontalSpacing];
  172. self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in AddTilesWatermarkTest.pdf\n"];
  173. }
  174. - (void)deletetWatermark:(CPDFDocument *)document {
  175. self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
  176. self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 4:Delete Watermark\n"];
  177. // Get Sandbox path for saving the PDF File
  178. NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
  179. NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"Watermark"];
  180. NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"Watermark",@"AddTextWatermarkTest"];
  181. // Copy file
  182. if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
  183. [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
  184. NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"DeleteWatermarkTest"];
  185. if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
  186. [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
  187. self.deleteWatermarkURL = [NSURL fileURLWithPath:writeFilePath];
  188. document = [[CPDFDocument alloc] initWithURL:self.deleteWatermarkURL];
  189. NSArray *waterArray = [document watermarks];
  190. [document removeWatermark:waterArray[0]];
  191. [document writeToURL:self.deleteWatermarkURL];
  192. self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in DeleteWatermarkTest.pdf\n"];
  193. }
  194. - (NSString *)getStringFromEnumVertalign:(NSInteger)enums {
  195. switch (enums) {
  196. case 0:
  197. return @"CPDFWatermarkVerticalPositionTop";
  198. break;
  199. case 1:
  200. return @"WATERMARK_VERTALIGN_CENTER";
  201. break;
  202. case 2:
  203. return @"CPDFWatermarkVerticalPositionBottom";
  204. break;
  205. default:
  206. return @" ";
  207. break;
  208. }
  209. }
  210. - (NSString *)getStringFromEnumHorizalign:(NSInteger)enums {
  211. switch (enums) {
  212. case 0:
  213. return @"CPDFWatermarkHorizontalPositionLeft";
  214. break;
  215. case 1:
  216. return @"CPDFWatermarkHorizontalPositionCenter";
  217. break;
  218. case 2:
  219. return @"CPDFWatermarkHorizontalPositionRight";
  220. break;
  221. default:
  222. return @" ";
  223. break;
  224. }
  225. }
  226. - (void)openFileWithURL:(NSURL *)url {
  227. UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:@[url] applicationActivities:nil];
  228. activityVC.definesPresentationContext = YES;
  229. if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
  230. activityVC.popoverPresentationController.sourceView = self.openfileButton;
  231. activityVC.popoverPresentationController.sourceRect = self.openfileButton.bounds;
  232. }
  233. [self presentViewController:activityVC animated:YES completion:nil];
  234. activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
  235. if (completed) {
  236. NSLog(@"Success!");
  237. } else {
  238. NSLog(@"Failed Or Canceled!");
  239. }
  240. };
  241. }
  242. #pragma mark - Action
  243. - (IBAction)buttonItemClick_openFile:(id)sender {
  244. // Determine whether to export the document
  245. if (self.isRun) {
  246. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Choose a file to open...", nil) message:@"" preferredStyle:UIAlertControllerStyleAlert];
  247. if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
  248. alertController.popoverPresentationController.sourceView = self.openfileButton;
  249. alertController.popoverPresentationController.sourceRect = self.openfileButton.bounds;
  250. }
  251. UIAlertAction *textWatermarkAction = [UIAlertAction actionWithTitle:NSLocalizedString(@" AddTextWatermarkTest.pdf ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  252. // Open AddTextWatermarkTest.pdf
  253. [self openFileWithURL:self.addTextWatermarkURL];
  254. }];
  255. UIAlertAction *imageWatermarkAction = [UIAlertAction actionWithTitle:NSLocalizedString(@" AddImageWatermarkTest.pdf ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  256. // Open AddImageWatermarkTest.pdf
  257. [self openFileWithURL:self.addImageWatermarkURL];
  258. }];
  259. UIAlertAction *tilesWatermarkAction = [UIAlertAction actionWithTitle:NSLocalizedString(@" AddTilesWatermarkTest.pdf ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  260. // Open AddTilesWatermarkTest.pdf
  261. [self openFileWithURL:self.addTilesWatermarkURL];
  262. }];
  263. UIAlertAction *deleteWatermarkAction = [UIAlertAction actionWithTitle:NSLocalizedString(@" DeleteWatermarkTest.pdf ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  264. // Open DeleteWatermarkTest.pdf
  265. [self openFileWithURL:self.deleteWatermarkURL];
  266. }];
  267. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];
  268. [alertController addAction:textWatermarkAction];
  269. [alertController addAction:imageWatermarkAction];
  270. [alertController addAction:tilesWatermarkAction];
  271. [alertController addAction:deleteWatermarkAction];
  272. [alertController addAction:cancelAction];
  273. [self presentViewController:alertController animated:NO completion:nil];
  274. } else {
  275. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Choose a file to open...", nil) message:@"" preferredStyle:UIAlertControllerStyleAlert];
  276. if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
  277. alertController.popoverPresentationController.sourceView = self.openfileButton;
  278. alertController.popoverPresentationController.sourceRect = self.openfileButton.bounds;
  279. }
  280. UIAlertAction *noAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"No files for this sample.", nil) style:UIAlertActionStyleDefault handler:nil];
  281. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];
  282. [alertController addAction:noAction];
  283. [alertController addAction:cancelAction];
  284. [self presentViewController:alertController animated:NO completion:nil];
  285. }
  286. }
  287. - (IBAction)buttonItemClick_run:(id)sender {
  288. if (self.document) {
  289. self.isRun = YES;
  290. self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Running Watermark sample...\n\n"];
  291. [self addTextWatermark:self.document];
  292. [self addImageWatermark:self.document];
  293. [self addTilesWatermark:self.document];
  294. [self deletetWatermark:self.document];
  295. self.commandLineStr = [self.commandLineStr stringByAppendingString:@"\nDone!\n"];
  296. self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
  297. // Refresh commandline message
  298. self.commandLineTextView.text = self.commandLineStr;
  299. } else {
  300. self.isRun = NO;
  301. self.commandLineStr = [self.commandLineStr stringByAppendingString:@"The document is null, can't open..\n\n"];
  302. self.commandLineTextView.text = self.commandLineStr;
  303. }
  304. }
  305. @end