|
@@ -10,22 +10,18 @@
|
|
|
#import "CPDFViewController.h"
|
|
|
#import "CPDFHeaderFooterAddController.h"
|
|
|
#import "CPDFHeaderFooterDeleteController.h"
|
|
|
-#import "CPDFBatesSettingController.h"
|
|
|
-#import "CPDFHeaderFooterSettingController.h"
|
|
|
+#import "CPDFBatesDeleteViewController.h"
|
|
|
+#import "CPDFBatesAddViewController.h"
|
|
|
#import "CPDFBatesModel.h"
|
|
|
|
|
|
@interface CPDFViewController () <UIActionSheetDelegate>
|
|
|
|
|
|
@property (nonatomic,strong) CPDFKitPlatformImage *image;
|
|
|
@property (nonatomic,assign) CGSize size;
|
|
|
-@property (nonatomic,strong) CPDFHeaderFooter *headerFooter;
|
|
|
-@property (nonatomic,strong) CPDFBates *bates;
|
|
|
@property (nonatomic,strong) CPDFDocument *document;
|
|
|
@property (nonatomic,strong) CPDFView *pdfView;
|
|
|
-@property (nonatomic,strong) CPDFHeaderFooterSettingController *headefooterControl;
|
|
|
@property (nonatomic,strong) CPDFHeaderFooterModel *modelData;
|
|
|
@property (nonatomic,strong) CPDFBatesModel *modelBatesData;
|
|
|
-@property (nonatomic,strong) CPDFBatesSettingController *batesBatesControl;
|
|
|
|
|
|
@end
|
|
|
|
|
@@ -41,73 +37,127 @@
|
|
|
- (void)viewDidLoad {
|
|
|
[super viewDidLoad];
|
|
|
// Do any additional setup after loading the view.
|
|
|
- //add UIBarButtonItem in Navigation
|
|
|
+ // Add UIBarButtonItem in Navigation
|
|
|
self.navigationController.toolbarHidden = YES;
|
|
|
UIImage *btnMore = [UIImage imageNamed:@"btn_more"];
|
|
|
UIBarButtonItem *ringhtBarItem = [[UIBarButtonItem alloc] initWithImage:btnMore style:UIBarButtonItemStylePlain target:self action:@selector(onClickedOkbtn)];
|
|
|
self.navigationItem.rightBarButtonItem = ringhtBarItem;
|
|
|
- //setting URL
|
|
|
+
|
|
|
+ // Setting URL
|
|
|
NSURL *url = [NSURL fileURLWithPath:_path];
|
|
|
_document = [[CPDFDocument alloc] initWithURL:url];
|
|
|
- //get document frist image
|
|
|
+
|
|
|
+ // Get document frist image
|
|
|
CPDFPage *page = [_document pageAtIndex:0];
|
|
|
_size = [_document pageSizeAtIndex:0];
|
|
|
_image = [page thumbnailOfSize:_size];
|
|
|
- //get document view
|
|
|
+
|
|
|
+ // Get document view
|
|
|
_pdfView = [[CPDFView alloc] initWithFrame:self.view.bounds];
|
|
|
_pdfView.document = _document;
|
|
|
_pdfView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
|
[self.view addSubview:_pdfView];
|
|
|
+
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getHeaderFooterModel:) name:@"getAddHeaderFooterModel" object:nil];
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deleteHeaderFooter:) name:@"deleteHeaderFooter" object:nil];
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getBatesMdel:) name:@"getAddBatesModel" object:nil];
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deleteBates:) name:@"deleteBatesModel" object:nil];
|
|
|
}
|
|
|
|
|
|
-#pragma mark - click event of CPDFViewController's ringhtBarItem
|
|
|
+#pragma mark - Actions
|
|
|
|
|
|
- (void)onClickedOkbtn {
|
|
|
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
|
|
- //add watermark action
|
|
|
+
|
|
|
+ // Add watermark action
|
|
|
UIAlertAction *addWatermarkAction = [UIAlertAction actionWithTitle:@"Add Watermark" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
NSLog(@"addWatermarkAction");
|
|
|
}];
|
|
|
- //setting headerfooter action
|
|
|
+
|
|
|
+ // Setting headerfooter action
|
|
|
UIAlertAction *settingHeaderFooter = [UIAlertAction actionWithTitle:@"Setting Headerfooter" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
- self.headefooterControl = [[CPDFHeaderFooterSettingController alloc] initWithIamge:self.image WithSize:self.size WithDocument:self.document WithView:self.pdfView];
|
|
|
- [self addChildViewController:self.headefooterControl];
|
|
|
- [self.view addSubview:self.headefooterControl.view];
|
|
|
- [self.navigationController pushViewController:self.headefooterControl animated:NO];
|
|
|
+
|
|
|
+ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
|
|
+
|
|
|
+ // Add headerfooter action
|
|
|
+ UIAlertAction *addHeaderfooterAction = [UIAlertAction actionWithTitle:@"Add Headerfooter" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+ CPDFHeaderFooterAddController *headerFooterControl = [[CPDFHeaderFooterAddController alloc] initWithIamge:self.image WithSize:self.size];
|
|
|
+
|
|
|
+ [self.navigationController pushViewController:headerFooterControl animated:NO];
|
|
|
+ }];
|
|
|
+
|
|
|
+ // Delete headerfooter action
|
|
|
+ UIAlertAction *deleteHeaderfooterAction = [UIAlertAction actionWithTitle:@"Delete Headerfooter" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+ CPDFHeaderFooterDeleteController *headerFooterDeleteControl = [[CPDFHeaderFooterDeleteController alloc] init];
|
|
|
+
|
|
|
+ [self addChildViewController:headerFooterDeleteControl];
|
|
|
+ [self.view addSubview:headerFooterDeleteControl.view];
|
|
|
+ }];
|
|
|
+
|
|
|
+ // Cancel Action
|
|
|
+ UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+ NSLog(@"Cancel Action");
|
|
|
+ }];
|
|
|
+
|
|
|
+ [alertController addAction:addHeaderfooterAction];
|
|
|
+ [alertController addAction:deleteHeaderfooterAction];
|
|
|
+ [alertController addAction:cancelAction];
|
|
|
+
|
|
|
+ [self presentViewController:alertController animated:YES completion:nil];
|
|
|
}];
|
|
|
- //seeting bates action
|
|
|
+
|
|
|
+ // Seeting bates action
|
|
|
UIAlertAction *settingBatesAction = [UIAlertAction actionWithTitle:@"Setting Bates" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
- self.batesBatesControl = [[CPDFBatesSettingController alloc] initWithIamge:self.image WithSize:self.size];
|
|
|
- [self addChildViewController:self.batesBatesControl];
|
|
|
- [self.view addSubview:self.batesBatesControl.view];
|
|
|
- [self.navigationController pushViewController:self.batesBatesControl animated:NO];
|
|
|
+ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
|
|
+
|
|
|
+ UIAlertAction *addBatesAction = [UIAlertAction actionWithTitle:@"Add Bates" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+ CPDFBatesAddViewController *batesAddControl = [[CPDFBatesAddViewController alloc] initWithIamge:self.image WithSize:self.size];
|
|
|
+
|
|
|
+ [self.navigationController pushViewController:batesAddControl animated:NO];
|
|
|
+ }];
|
|
|
+
|
|
|
+ UIAlertAction *delereBatesAction = [UIAlertAction actionWithTitle:@"Delete Bates" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+ CPDFBatesDeleteViewController *batesDeleteControl = [[CPDFBatesDeleteViewController alloc] init];
|
|
|
+
|
|
|
+ [self addChildViewController:batesDeleteControl];
|
|
|
+ [self.view addSubview:batesDeleteControl.view];
|
|
|
+ }];
|
|
|
+
|
|
|
+ UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+ NSLog(@"Cancel Action");
|
|
|
+ }];
|
|
|
+
|
|
|
+ [alertController addAction:addBatesAction];
|
|
|
+ [alertController addAction:delereBatesAction];
|
|
|
+ [alertController addAction:cancelAction];
|
|
|
+
|
|
|
+ [self presentViewController:alertController animated:YES completion:nil];
|
|
|
}];
|
|
|
- //cancel action
|
|
|
+
|
|
|
+ // Cancel action
|
|
|
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
|
|
|
NSLog(@"Cancel Action");
|
|
|
}];
|
|
|
+
|
|
|
+ // Add controller
|
|
|
[alertController addAction:addWatermarkAction];
|
|
|
[alertController addAction:settingHeaderFooter];
|
|
|
[alertController addAction:settingBatesAction];
|
|
|
[alertController addAction:cancelAction];
|
|
|
- [self presentViewController:alertController animated:YES completion:nil];
|
|
|
- self.pdfView = self.headefooterControl.pdfView;
|
|
|
- [self.view addSubview:self.pdfView];
|
|
|
|
|
|
+ [self presentViewController:alertController animated:YES completion:nil];
|
|
|
}
|
|
|
|
|
|
-#pragma mark - add headerfooter function
|
|
|
+#pragma mark - Function
|
|
|
|
|
|
-//get headerfooter' model to setting page headerfooter's add functional property
|
|
|
+// Get headerfooter' model to setting page headerfooter's add functional property
|
|
|
- (void)getHeaderFooterModel:(NSNotification *)addSign {
|
|
|
_modelData = addSign.userInfo[@"model"];
|
|
|
- _headerFooter = [self.document headerFooter];
|
|
|
+ CPDFHeaderFooter *headerFooter = [self.document headerFooter];
|
|
|
+
|
|
|
NSString *pageIndex = [NSString stringWithFormat:@"0-%lu",self.document.pageCount - 1];
|
|
|
NSString *text = [[NSString alloc] init];
|
|
|
+
|
|
|
switch (_modelData.fontSelcet) {
|
|
|
case 0:
|
|
|
text = [NSString stringWithFormat:@"<<%@>>",self.modelData.pageStart];
|
|
@@ -127,72 +177,74 @@
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
- self.headerFooter.pageString = pageIndex;
|
|
|
- [_headerFooter setText:text atIndex:self.modelData.fontPosition];
|
|
|
- [_headerFooter setFontSize:self.modelData.fontSize atIndex:self.modelData.fontPosition];
|
|
|
- [_headerFooter setTextColor:self.modelData.fontColor atIndex:self.modelData.fontPosition];
|
|
|
- [_headerFooter update];
|
|
|
+
|
|
|
+ headerFooter.pageString = pageIndex;
|
|
|
+ [headerFooter setText:text atIndex:self.modelData.fontPosition];
|
|
|
+ [headerFooter setFontSize:self.modelData.fontSize atIndex:self.modelData.fontPosition];
|
|
|
+ [headerFooter setTextColor:self.modelData.fontColor atIndex:self.modelData.fontPosition];
|
|
|
+ [headerFooter update];
|
|
|
+
|
|
|
NSURL *url = [NSURL fileURLWithPath:self.path];
|
|
|
[self.document writeToURL:url];
|
|
|
_document = [[CPDFDocument alloc] initWithURL:url];
|
|
|
_pdfView = [[CPDFView alloc] initWithFrame:self.view.bounds];
|
|
|
_pdfView.document = _document;
|
|
|
_pdfView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
|
+
|
|
|
[self.view addSubview:_pdfView];
|
|
|
}
|
|
|
|
|
|
-#pragma mark - add bates function
|
|
|
-
|
|
|
-//get bates' model to setting page bates's add functional property
|
|
|
+// Get bates' model to setting page bates's add functional property
|
|
|
- (void)getBatesMdel:(NSNotification *)addBatesSign {
|
|
|
_modelBatesData = addBatesSign.userInfo[@"batesModel"];
|
|
|
- _bates = [self.document bates];
|
|
|
+ CPDFBates *bates = [self.document bates];
|
|
|
+
|
|
|
NSString *pageIndex = [NSString stringWithFormat:@"%@-%lu",self.modelBatesData.pageStart,self.document.pageCount - 1];
|
|
|
- self.bates.pageString = pageIndex;
|
|
|
+ bates.pageString = pageIndex;
|
|
|
NSString *text = [NSString stringWithFormat:@"<<%@>>",self.modelBatesData.fontText];
|
|
|
- [_bates setText:text atIndex:self.modelBatesData.fontPosition];
|
|
|
- [_bates setFontName:self.modelBatesData.fontName atIndex:self.modelBatesData.fontPosition];
|
|
|
- [_bates setFontSize:15.0 atIndex:self.modelBatesData.fontPosition];
|
|
|
- [_bates setTextColor:self.modelBatesData.fontColor atIndex:self.modelBatesData.fontPosition];
|
|
|
- [_bates update];
|
|
|
- NSString *test = [self.bates textAtIndex:self.modelBatesData.fontPosition];
|
|
|
- NSLog(@"%@",test);
|
|
|
+ [bates setText:text atIndex:self.modelBatesData.fontPosition];
|
|
|
+ [bates setFontName:self.modelBatesData.fontName atIndex:self.modelBatesData.fontPosition];
|
|
|
+ [bates setFontSize:15.0 atIndex:self.modelBatesData.fontPosition];
|
|
|
+ [bates setTextColor:self.modelBatesData.fontColor atIndex:self.modelBatesData.fontPosition];
|
|
|
+ [bates update];
|
|
|
+
|
|
|
NSURL *url = [NSURL fileURLWithPath:self.path];
|
|
|
[self.document writeToURL:url];
|
|
|
_document = [[CPDFDocument alloc] initWithURL:url];
|
|
|
_pdfView = [[CPDFView alloc] initWithFrame:self.view.bounds];
|
|
|
_pdfView.document = _document;
|
|
|
_pdfView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
|
+
|
|
|
[self.view addSubview:_pdfView];
|
|
|
}
|
|
|
|
|
|
-#pragma mark - delete headerfooter function
|
|
|
-
|
|
|
-//get headerfooter' model to setting page headerfooter's delete functional property
|
|
|
+// Get headerfooter' model to setting page headerfooter's delete functional property
|
|
|
- (void)deleteHeaderFooter:(NSNotification *)deleteSign {
|
|
|
- _headerFooter = [self.document headerFooter];
|
|
|
- [_headerFooter clear];
|
|
|
+ CPDFHeaderFooter *headerFooter = [self.document headerFooter];
|
|
|
+ [headerFooter clear];
|
|
|
+
|
|
|
NSURL *url = [NSURL fileURLWithPath:self.path];
|
|
|
[self.document writeToURL:url];
|
|
|
_document = [[CPDFDocument alloc] initWithURL:url];
|
|
|
_pdfView = [[CPDFView alloc] initWithFrame:self.view.bounds];
|
|
|
_pdfView.document = _document;
|
|
|
_pdfView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
|
+
|
|
|
[self.view addSubview:_pdfView];
|
|
|
}
|
|
|
|
|
|
-#pragma mark - delete bates function
|
|
|
-
|
|
|
-//get bates' model to setting page bates's delete functional property
|
|
|
+// Get bates' model to setting page bates's delete functional property
|
|
|
- (void)deleteBates:(NSNotification *)deleteBates {
|
|
|
- _bates = [self.document bates];
|
|
|
- [_bates clear];
|
|
|
+ CPDFBates *bates = [self.document bates];
|
|
|
+ [bates clear];
|
|
|
+
|
|
|
NSURL *url = [NSURL fileURLWithPath:self.path];
|
|
|
[self.document writeToURL:url];
|
|
|
_document = [[CPDFDocument alloc] initWithURL:url];
|
|
|
_pdfView = [[CPDFView alloc] initWithFrame:self.view.bounds];
|
|
|
_pdfView.document = _document;
|
|
|
_pdfView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
|
+
|
|
|
[self.view addSubview:_pdfView];
|
|
|
}
|
|
|
|