|
@@ -19,16 +19,16 @@
|
|
#import "CPDFDataModel.h"
|
|
#import "CPDFDataModel.h"
|
|
#import "Masonry.h"
|
|
#import "Masonry.h"
|
|
|
|
|
|
-#define KSCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width
|
|
|
|
-#define KSCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height
|
|
|
|
|
|
|
|
@interface CPDFViewController () <UIActionSheetDelegate>
|
|
@interface CPDFViewController () <UIActionSheetDelegate>
|
|
|
|
|
|
@property (nonatomic,strong) CPDFTextViewController *textViewController;
|
|
@property (nonatomic,strong) CPDFTextViewController *textViewController;
|
|
@property (nonatomic,strong) CPDFImageViewController *imageViewController;
|
|
@property (nonatomic,strong) CPDFImageViewController *imageViewController;
|
|
@property (nonatomic,strong) CPDFView *pdfView;
|
|
@property (nonatomic,strong) CPDFView *pdfView;
|
|
|
|
+@property (nonatomic,strong) CPDFDocument *pdfDocument;
|
|
@property (nonatomic,strong) CPDFWatermark *textWatermark;
|
|
@property (nonatomic,strong) CPDFWatermark *textWatermark;
|
|
@property (nonatomic,strong) CPDFWatermark *imageWatermark;
|
|
@property (nonatomic,strong) CPDFWatermark *imageWatermark;
|
|
|
|
+@property (nonatomic,assign) CGSize imageSize;
|
|
|
|
|
|
@end
|
|
@end
|
|
|
|
|
|
@@ -45,15 +45,16 @@
|
|
[super viewDidLoad];
|
|
[super viewDidLoad];
|
|
// Do any additional setup after loading the view.
|
|
// Do any additional setup after loading the view.
|
|
//add UIBarButtonItem in Navigation
|
|
//add UIBarButtonItem in Navigation
|
|
- self.navigationController.toolbarHidden = NO;
|
|
|
|
|
|
+ self.navigationController.toolbarHidden = YES;
|
|
UIImage *btnMore = [UIImage imageNamed:@"btn_more"];
|
|
UIImage *btnMore = [UIImage imageNamed:@"btn_more"];
|
|
UIBarButtonItem *ringhtBarItem = [[UIBarButtonItem alloc] initWithImage:btnMore style:UIBarButtonItemStylePlain target:self action:@selector(onClickedOkbtn)];
|
|
UIBarButtonItem *ringhtBarItem = [[UIBarButtonItem alloc] initWithImage:btnMore style:UIBarButtonItemStylePlain target:self action:@selector(onClickedOkbtn)];
|
|
self.navigationItem.rightBarButtonItem = ringhtBarItem;
|
|
self.navigationItem.rightBarButtonItem = ringhtBarItem;
|
|
|
|
+
|
|
//setting URL
|
|
//setting URL
|
|
NSURL *url = [NSURL fileURLWithPath:_path];
|
|
NSURL *url = [NSURL fileURLWithPath:_path];
|
|
- CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];
|
|
|
|
|
|
+ _pdfDocument = [[CPDFDocument alloc] initWithURL:url];
|
|
_pdfView = [[CPDFView alloc] initWithFrame:self.view.bounds];
|
|
_pdfView = [[CPDFView alloc] initWithFrame:self.view.bounds];
|
|
- _pdfView.document = document;
|
|
|
|
|
|
+ _pdfView.document = _pdfDocument;
|
|
_pdfView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
_pdfView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
[self.view addSubview:_pdfView];
|
|
[self.view addSubview:_pdfView];
|
|
}
|
|
}
|
|
@@ -79,14 +80,14 @@
|
|
[self.view addSubview:_imageViewController.view];
|
|
[self.view addSubview:_imageViewController.view];
|
|
|
|
|
|
CPDFPage *pdfPage = [_pdfView.document pageAtIndex:0];
|
|
CPDFPage *pdfPage = [_pdfView.document pageAtIndex:0];
|
|
- CGSize size = [_pdfView.document pageSizeAtIndex:0];
|
|
|
|
- _textViewController.textPreview.documentView.image = [pdfPage thumbnailOfSize:size];
|
|
|
|
- _imageViewController.imagePreview.documentView.image = [pdfPage thumbnailOfSize:size];
|
|
|
|
|
|
+ _imageSize = [_pdfView.document pageSizeAtIndex:0];
|
|
|
|
+ _textViewController.textPreview.documentView.image = [pdfPage thumbnailOfSize:_imageSize];
|
|
|
|
+ _imageViewController.imagePreview.documentView.image = [pdfPage thumbnailOfSize:_imageSize];
|
|
_imageViewController.view.hidden = YES;
|
|
_imageViewController.view.hidden = YES;
|
|
_pdfView.hidden = YES;
|
|
_pdfView.hidden = YES;
|
|
|
|
|
|
- _textWatermark = [[CPDFWatermark alloc] initWithDocument:_pdfView.document type:CPDFWatermarkTypeText];
|
|
|
|
- _imageWatermark = [[CPDFWatermark alloc] initWithDocument:_pdfView.document type:CPDFWatermarkTypeImage];
|
|
|
|
|
|
+ _textWatermark = [[CPDFWatermark alloc] initWithDocument:_pdfDocument type:CPDFWatermarkTypeText];
|
|
|
|
+ _imageWatermark = [[CPDFWatermark alloc] initWithDocument:_pdfDocument type:CPDFWatermarkTypeImage];
|
|
}
|
|
}
|
|
|
|
|
|
- (void)segmentedAction:(UISegmentedControl *)sender {
|
|
- (void)segmentedAction:(UISegmentedControl *)sender {
|
|
@@ -104,29 +105,92 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-- (void)createFrame {
|
|
|
|
- NSSet *set = [UIApplication sharedApplication].connectedScenes;
|
|
|
|
- UIWindowScene *windowScene = [set anyObject];
|
|
|
|
- UIStatusBarManager *statusBarManager = windowScene.statusBarManager;
|
|
|
|
- _segmentedControl.frame = CGRectMake(0, statusBarManager.statusBarFrame.size.height + self.navigationController.navigationBar.frame.size
|
|
|
|
- .height, KSCREEN_WIDTH, KSCREEN_HEIGHT / 20);
|
|
|
|
- _segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
|
|
|
|
|
|
+- (void)addConstraint {
|
|
|
|
+
|
|
|
|
+ [_segmentedControl mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
+ make.top.equalTo(self.navigationController.navigationBar.mas_bottom).offset(0);
|
|
|
|
+ make.width.equalTo(self.view.mas_width);
|
|
|
|
+ make.height.equalTo(@(self.view.bounds.size.height / 20));
|
|
|
|
+ }];
|
|
|
|
|
|
- UIEdgeInsets padding = UIEdgeInsetsMake(statusBarManager.statusBarFrame.size.height + self.navigationController.navigationBar.frame.size
|
|
|
|
- .height + KSCREEN_HEIGHT / 20, 0, 0, 0);
|
|
|
|
[_textViewController.view mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
[_textViewController.view mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
- make.edges.equalTo(self.view).with.insets(padding);
|
|
|
|
|
|
+ make.top.equalTo(_segmentedControl.mas_bottom).offset(0);
|
|
|
|
+ make.width.equalTo(_segmentedControl.mas_width);
|
|
|
|
+ make.bottom.equalTo(self.view).offset(0);
|
|
}];
|
|
}];
|
|
[_imageViewController.view mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
[_imageViewController.view mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
- make.edges.equalTo(self.view).with.insets(padding);
|
|
|
|
|
|
+ make.top.equalTo(_segmentedControl.mas_bottom).offset(0);
|
|
|
|
+ make.width.equalTo(_segmentedControl.mas_width);
|
|
|
|
+ make.bottom.equalTo(self.view).offset(0);
|
|
|
|
+ }];
|
|
|
|
+ [_textViewController.textPreview.documentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
+ make.centerX.equalTo(_textViewController.textPreview.mas_centerX);
|
|
|
|
+ make.centerY.equalTo(_textViewController.textPreview.mas_centerY);
|
|
|
|
+ make.width.equalTo(@(_imageSize.width / 2));
|
|
|
|
+ make.height.equalTo(@(_imageSize.height / 2));
|
|
|
|
+ }];
|
|
|
|
+ [_imageViewController.imagePreview.documentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
+ make.centerX.equalTo(_imageViewController.imagePreview.mas_centerX);
|
|
|
|
+ make.centerY.equalTo(_imageViewController.imagePreview.mas_centerY);
|
|
|
|
+ make.width.equalTo(@(_imageSize.width / 2));
|
|
|
|
+ make.height.equalTo(@(_imageSize.height / 2));
|
|
}];
|
|
}];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
|
|
|
|
+ [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
|
|
|
|
+ if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
|
|
|
|
+
|
|
|
|
+ if (_imageSize.width > _imageSize.height) {
|
|
|
|
+ [_textViewController.textPreview.documentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
+ make.centerX.equalTo(_textViewController.textPreview.mas_centerX);
|
|
|
|
+ make.centerY.equalTo(_textViewController.textPreview.mas_centerY);
|
|
|
|
+ make.width.equalTo(@(_imageSize.width / 3.1));
|
|
|
|
+ make.height.equalTo(@(_imageSize.height / 2.6));
|
|
|
|
+ }];
|
|
|
|
+ [_imageViewController.imagePreview.documentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
+ make.centerX.equalTo(_imageViewController.imagePreview.mas_centerX);
|
|
|
|
+ make.centerY.equalTo(_imageViewController.imagePreview.mas_centerY);
|
|
|
|
+ make.width.equalTo(@(_imageSize.width / 3.1));
|
|
|
|
+ make.height.equalTo(@(_imageSize.height / 2.6));
|
|
|
|
+ }];
|
|
|
|
+ } else {
|
|
|
|
+ [_textViewController.textPreview.documentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
+ make.centerX.equalTo(_textViewController.textPreview.mas_centerX);
|
|
|
|
+ make.centerY.equalTo(_textViewController.textPreview.mas_centerY);
|
|
|
|
+ make.width.equalTo(@(_imageSize.width / 2.4));
|
|
|
|
+ make.height.equalTo(@(_imageSize.height / 2.9));
|
|
|
|
+ }];
|
|
|
|
+ [_imageViewController.imagePreview.documentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
+ make.centerX.equalTo(_imageViewController.imagePreview.mas_centerX);
|
|
|
|
+ make.centerY.equalTo(_imageViewController.imagePreview.mas_centerY);
|
|
|
|
+ make.width.equalTo(@(_imageSize.width / 2.4));
|
|
|
|
+ make.height.equalTo(@(_imageSize.height / 2.9));
|
|
|
|
+ }];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
|
|
|
|
+
|
|
|
|
+ [_textViewController.textPreview.documentView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
+ make.centerX.equalTo(_textViewController.textPreview.mas_centerX);
|
|
|
|
+ make.centerY.equalTo(_textViewController.textPreview.mas_centerY);
|
|
|
|
+ make.width.equalTo(@(_imageSize.width / 2));
|
|
|
|
+ make.height.equalTo(@(_imageSize.height / 2));
|
|
|
|
+ }];
|
|
|
|
+ [_imageViewController.imagePreview.documentView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
+ make.centerX.equalTo(_imageViewController.imagePreview.mas_centerX);
|
|
|
|
+ make.centerY.equalTo(_imageViewController.imagePreview.mas_centerY);
|
|
|
|
+ make.width.equalTo(@(_imageSize.width / 2));
|
|
|
|
+ make.height.equalTo(@(_imageSize.height / 2));
|
|
|
|
+ }];
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
- (void)onClickedOkbtn {
|
|
- (void)onClickedOkbtn {
|
|
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
|
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
|
UIAlertAction *addWatermarkAction = [UIAlertAction actionWithTitle:@"Add Watermark" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
UIAlertAction *addWatermarkAction = [UIAlertAction actionWithTitle:@"Add Watermark" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
[self createView];
|
|
[self createView];
|
|
- [self createFrame];
|
|
|
|
|
|
+ [self addConstraint];
|
|
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(onClickedDoneBtn)];
|
|
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(onClickedDoneBtn)];
|
|
self.navigationItem.rightBarButtonItem = doneBtn;
|
|
self.navigationItem.rightBarButtonItem = doneBtn;
|
|
}];
|
|
}];
|
|
@@ -134,7 +198,7 @@
|
|
NSLog(@"addHeaderfooterAction");
|
|
NSLog(@"addHeaderfooterAction");
|
|
}];
|
|
}];
|
|
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
|
|
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
|
|
- NSLog(@"Cancel Action");
|
|
|
|
|
|
+
|
|
}];
|
|
}];
|
|
[alertController addAction:addWatermarkAction];
|
|
[alertController addAction:addWatermarkAction];
|
|
[alertController addAction:addHeaderfooterAction];
|
|
[alertController addAction:addHeaderfooterAction];
|
|
@@ -151,17 +215,53 @@
|
|
_segmentedControl.hidden = YES;
|
|
_segmentedControl.hidden = YES;
|
|
|
|
|
|
if (_segmentedControl.selectedSegmentIndex == 0) {
|
|
if (_segmentedControl.selectedSegmentIndex == 0) {
|
|
- _textWatermark.text = @"Watermark";
|
|
|
|
|
|
+
|
|
|
|
+ _textWatermark.text = _textViewController.dataModel.text;
|
|
_textWatermark.textColor = _textViewController.dataModel.textColor;
|
|
_textWatermark.textColor = _textViewController.dataModel.textColor;
|
|
_textWatermark.opacity = _textViewController.dataModel.watermarkOpacity;
|
|
_textWatermark.opacity = _textViewController.dataModel.watermarkOpacity;
|
|
_textWatermark.scale = _textViewController.dataModel.watermarkScale;
|
|
_textWatermark.scale = _textViewController.dataModel.watermarkScale;
|
|
_textWatermark.isTilePage = _textViewController.dataModel.isTile;
|
|
_textWatermark.isTilePage = _textViewController.dataModel.isTile;
|
|
|
|
+ _textWatermark.tx = _textViewController.dataModel.tx;
|
|
|
|
+ _textWatermark.ty = _textViewController.dataModel.ty;
|
|
|
|
+ _textWatermark.rotation = _textViewController.dataModel.watermarkRotation;
|
|
|
|
+
|
|
|
|
+ if (_textWatermark.isTilePage) {
|
|
|
|
+ _textWatermark.verticalSpacing = [_textViewController.textView.verticalField.text floatValue];
|
|
|
|
+ _textWatermark.horizontalSpacing = [_textViewController.textView.horizontalField.text floatValue];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (_textViewController.dataModel.pageString) {
|
|
|
|
+ _textWatermark.pageString = _textViewController.dataModel.pageString;
|
|
|
|
+ }
|
|
|
|
+
|
|
[_pdfView.document addWatermark:_textWatermark];
|
|
[_pdfView.document addWatermark:_textWatermark];
|
|
|
|
+ [_pdfView layoutDocumentView];
|
|
|
|
+// NSURL *url = [NSURL fileURLWithPath:_path];
|
|
|
|
+// [_pdfView.document writeToURL:url];
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
|
|
+ _imageWatermark.image = [UIImage imageNamed:_imageViewController.dataModel.imagePath];
|
|
|
|
+ _imageWatermark.opacity = _imageViewController.dataModel.watermarkOpacity;
|
|
|
|
+ _imageWatermark.scale = _imageViewController.dataModel.watermarkScale;
|
|
|
|
+ _imageWatermark.isTilePage = _imageViewController.dataModel.isTile;
|
|
|
|
+ _imageWatermark.tx = _imageViewController.dataModel.tx;
|
|
|
|
+ _imageWatermark.ty = _imageViewController.dataModel.ty;
|
|
|
|
+ _imageWatermark.rotation = _imageViewController.dataModel.watermarkRotation;
|
|
|
|
+
|
|
|
|
+ if (_imageWatermark.isTilePage) {
|
|
|
|
+ _imageWatermark.verticalSpacing = [_imageViewController.imageView.verticalField.text floatValue];
|
|
|
|
+ _imageWatermark.horizontalSpacing = [_imageViewController.imageView.horizontalField.text floatValue];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (_imageViewController.dataModel.pageString) {
|
|
|
|
+ _imageWatermark.pageString = _imageViewController.dataModel.pageString;
|
|
|
|
+ }
|
|
|
|
|
|
[_pdfView.document addWatermark:_imageWatermark];
|
|
[_pdfView.document addWatermark:_imageWatermark];
|
|
|
|
+ [_pdfView layoutDocumentView];
|
|
|
|
+// NSURL *url = [NSURL fileURLWithPath:_path];
|
|
|
|
+// [_pdfView.document writeContentToURL:url];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|