瀏覽代碼

Merge branch 'compdfkit_demo_ios' of git.kdan.cc:others/kmpdfkit_demo into compdfkit_demo_ios

chenyu 1 年之前
父節點
當前提交
05ef0adc47

+ 27 - 5
Form-Ctrl-Demo/Form-Ctrl-Demo/CPDFViewController.m

@@ -16,10 +16,11 @@
 #import <compdfkit_tools/compdfkit_tools.h>
 
 
-@interface CPDFViewController () <CPDFToolsViewControllerDelegate,CPDFFormBarDelegate,CPDFBOTAViewControllerDelegate,CPDFListViewDelegate>
+@interface CPDFViewController () <CPDFToolsViewControllerDelegate,CPDFFormBarDelegate,CPDFBOTAViewControllerDelegate,CPDFListViewDelegate,CPDFSignatureViewControllerDelegate>
 
 @property(nonatomic, strong) CPDFFormBar * formBar;
 @property(nonatomic, strong) CAnnotationManage *annotationManage;
+@property(nonatomic, strong) CPDFSignatureWidgetAnnotation * signatureAnnotation;
 
 @end
 
@@ -328,10 +329,17 @@
 //    }
 //}
 //
-//- (void)PDFListViewPerformSignatureWidget:(CPDFListView *)pdfView forAnnotation:(CPDFSignatureWidgetAnnotation *)annotation {
-//    [self.annotationBar openSignatureAnnotation:annotation];
-//}
-//
+- (void)PDFListViewPerformSignatureWidget:(CPDFListView *)pdfView forAnnotation:(CPDFSignatureWidgetAnnotation *)annotation {
+    if(CToolModelViewer == self.pdfListView.toolModel) {
+        self.signatureAnnotation = annotation;
+        AAPLCustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
+        CPDFSignatureViewController *signatureVC = [[CPDFSignatureViewController alloc] initWithStyle:nil];
+        presentationController = [[AAPLCustomPresentationController alloc] initWithPresentedViewController:signatureVC presentingViewController:self];
+        signatureVC.delegate = self;
+        signatureVC.transitioningDelegate = presentationController;
+        [self presentViewController:signatureVC animated:YES completion:nil];
+    }
+}
 
 - (void)PDFListViewEditWidget:(CPDFListView *)pdfListView forAnnotation:(CPDFAnnotation *)annotation {
     [self.formBar buttonItemClicked_openOption:annotation];
@@ -461,4 +469,18 @@
     }
 }
 
+#pragma mark - CPDFSignatureViewControllerDelegate
+
+- (void)signatureViewControllerDismiss:(CPDFSignatureViewController *)signatureViewController {
+    self.signatureAnnotation = nil;
+}
+
+- (void)signatureViewController:(CPDFSignatureViewController *)signatureViewController image:(UIImage *)image {
+    if(self.signatureAnnotation) {
+        [self.signatureAnnotation signWithImage:image];
+        [self.pdfListView setNeedsDisplayForPage:self.signatureAnnotation.page];
+        self.signatureAnnotation = nil;
+    }
+}
+
 @end

+ 12 - 0
compdfkit-tools/compdfkit-tools.xcodeproj/project.pbxproj

@@ -176,6 +176,9 @@
 		C9C58E6F2A24CB0500B349F4 /* CBlankPageModel.m in Sources */ = {isa = PBXBuildFile; fileRef = C9C58E6D2A24CB0500B349F4 /* CBlankPageModel.m */; };
 		C9C58E722A25EC4600B349F4 /* CPDFPDFInsertViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = C9C58E702A25EC4600B349F4 /* CPDFPDFInsertViewController.h */; };
 		C9C58E732A25EC4600B349F4 /* CPDFPDFInsertViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C9C58E712A25EC4600B349F4 /* CPDFPDFInsertViewController.m */; };
+		C9C58E762A29C9D500B349F4 /* CDocumentPasswordViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = C9C58E742A29C9D500B349F4 /* CDocumentPasswordViewController.h */; };
+		C9C58E772A29C9D500B349F4 /* CDocumentPasswordViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C9C58E752A29C9D500B349F4 /* CDocumentPasswordViewController.m */; };
+		C9C58E792A29CC2800B349F4 /* Image.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C9C58E782A29CC2800B349F4 /* Image.xcassets */; };
 		C9C6EF282A2050BA00E1DD81 /* CPDFPageEditViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = C9C6EF262A2050BA00E1DD81 /* CPDFPageEditViewCell.h */; };
 		C9C6EF292A2050BA00E1DD81 /* CPDFPageEditViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C9C6EF272A2050BA00E1DD81 /* CPDFPageEditViewCell.m */; };
 		C9C6EF2C2A2056B000E1DD81 /* CPDFPageEditViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = C9C6EF2A2A2056B000E1DD81 /* CPDFPageEditViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -490,6 +493,9 @@
 		C9C58E6D2A24CB0500B349F4 /* CBlankPageModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CBlankPageModel.m; sourceTree = "<group>"; };
 		C9C58E702A25EC4600B349F4 /* CPDFPDFInsertViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CPDFPDFInsertViewController.h; sourceTree = "<group>"; };
 		C9C58E712A25EC4600B349F4 /* CPDFPDFInsertViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CPDFPDFInsertViewController.m; sourceTree = "<group>"; };
+		C9C58E742A29C9D500B349F4 /* CDocumentPasswordViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CDocumentPasswordViewController.h; sourceTree = "<group>"; };
+		C9C58E752A29C9D500B349F4 /* CDocumentPasswordViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CDocumentPasswordViewController.m; sourceTree = "<group>"; };
+		C9C58E782A29CC2800B349F4 /* Image.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Image.xcassets; sourceTree = "<group>"; };
 		C9C6EF262A2050BA00E1DD81 /* CPDFPageEditViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CPDFPageEditViewCell.h; sourceTree = "<group>"; };
 		C9C6EF272A2050BA00E1DD81 /* CPDFPageEditViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CPDFPageEditViewCell.m; sourceTree = "<group>"; };
 		C9C6EF2A2A2056B000E1DD81 /* CPDFPageEditViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CPDFPageEditViewController.h; sourceTree = "<group>"; };
@@ -936,6 +942,9 @@
 				F38F60C529EFF0C1008098F8 /* CPDFColorUtils.m */,
 				4F59868F2A03411700F06A1B /* CPDFDropDownMenu.h */,
 				4F5986902A03411700F06A1B /* CPDFDropDownMenu.m */,
+				C9C58E742A29C9D500B349F4 /* CDocumentPasswordViewController.h */,
+				C9C58E752A29C9D500B349F4 /* CDocumentPasswordViewController.m */,
+				C9C58E782A29CC2800B349F4 /* Image.xcassets */,
 			);
 			path = Utils;
 			sourceTree = "<group>";
@@ -1516,6 +1525,7 @@
 				C91BE7E22A048F1A0038F2BC /* CSignatureManager.h in Headers */,
 				4F8C15A02A26DC260065B001 /* UIResponder+FirstResponder.h in Headers */,
 				C9FBA23B2A135F50003FABEC /* CShapeSelectView.h in Headers */,
+				C9C58E762A29C9D500B349F4 /* CDocumentPasswordViewController.h in Headers */,
 				F35DD19F2A06850700B57F5B /* CPDFCircleAnnotation+PDFListView.h in Headers */,
 				F32054C92A0F819F006B41F7 /* CPDFSoundPlayBar.h in Headers */,
 				C91BE7D82A039D2A0038F2BC /* CPDFSignatureViewCell.h in Headers */,
@@ -1669,6 +1679,7 @@
 				C918CED129FA490000D43974 /* Image.xcassets in Resources */,
 				F32DA16E29ED904300E19ECA /* Images.xcassets in Resources */,
 				F32DA18629ED904300E19ECA /* Image.xcassets in Resources */,
+				C9C58E792A29CC2800B349F4 /* Image.xcassets in Resources */,
 				F3E8495929E69712007BE967 /* DisplayImage.xcassets in Resources */,
 				F32DA17C29ED904300E19ECA /* DisplayImage.xcassets in Resources */,
 				F32DA16329ED904300E19ECA /* Image.xcassets in Resources */,
@@ -1727,6 +1738,7 @@
 				4F5C3B912A2056EC00EBF9B5 /* CPDFFontSettingView.m in Sources */,
 				C9E792D12A1CE2CF0013D6A8 /* CPDFEditImageSampleView.m in Sources */,
 				4F8C15A22A26DC260065B001 /* WPAutoSpringTextViewController.m in Sources */,
+				C9C58E772A29C9D500B349F4 /* CDocumentPasswordViewController.m in Sources */,
 				F32DA17329ED904300E19ECA /* CPDFThumbnailViewController.m in Sources */,
 				C91BE7C42A02352B0038F2BC /* CPDFFreeTextViewController.m in Sources */,
 				C918CEDC29FB73C800D43974 /* CPDFArrowStyleView.m in Sources */,

+ 38 - 0
compdfkit-tools/compdfkit-tools/Common/Utils/CDocumentPasswordViewController.h

@@ -0,0 +1,38 @@
+//
+//  CDocumentPasswordViewController.h
+//  compdfkit-tools
+//
+//  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 <UIKit/UIKit.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@class CPDFDocument;
+@class CDocumentPasswordViewController;
+
+@protocol CDocumentPasswordViewControllerDelegate <NSObject>
+
+@optional
+
+- (void)documentPasswordViewControllerCancel:(CDocumentPasswordViewController *)documentPasswordViewController;
+
+- (void)documentPasswordViewControllerOpen:(CDocumentPasswordViewController *)documentPasswordViewController;
+
+@end
+
+@interface CDocumentPasswordViewController : UIViewController
+
+@property (nonatomic, weak) id<CDocumentPasswordViewControllerDelegate> delegate;
+
+- (instancetype)initWithDocument:(CPDFDocument *)document;
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 204 - 0
compdfkit-tools/compdfkit-tools/Common/Utils/CDocumentPasswordViewController.m

@@ -0,0 +1,204 @@
+//
+//  CDocumentPasswordViewController.m
+//  compdfkit-tools
+//
+//  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 "CDocumentPasswordViewController.h"
+#import "CPDFColorUtils.h"
+
+#import <ComPDFKit/ComPDFKit.h>
+
+@interface CDocumentPasswordViewController () <UITextFieldDelegate>
+
+@property (nonatomic, strong) UIButton *backBtn;
+
+@property (nonatomic, strong) UIImageView *passwordImageView;
+
+@property (nonatomic, strong) UILabel *titleLablel;
+
+@property (nonatomic, strong) UIView *enterView;
+
+@property (nonatomic, strong) UILabel *passLabel;
+
+@property (nonatomic, strong) UIView *splitVidew;
+
+@property (nonatomic, strong) UITextField *enterTextField;
+
+@property (nonatomic, strong) UILabel *warningLabel;
+
+@property (nonatomic, strong) UIButton *OKBtn;
+
+@property (nonatomic, strong) CPDFDocument *document;
+
+@property (nonatomic, strong) UIButton *clearButton;
+
+@end
+
+@implementation CDocumentPasswordViewController
+
+#pragma mark - Initializers
+
+- (instancetype)initWithDocument:(CPDFDocument *)document {
+    if (self = [super init]) {
+        self.document = document;
+    }
+    return self;
+}
+
+
+#pragma mark - UIViewController Methods
+
+- (void)viewDidLoad {
+    [super viewDidLoad];
+    // Do any additional setup after loading the view.
+    self.backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
+    [self.backBtn setImage:[UIImage imageNamed:@"CDocumentPasswordImageBack" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
+    [self.backBtn addTarget:self action:@selector(buttonItemClicked_back:) forControlEvents:UIControlEventTouchUpInside];
+    [self.view addSubview:self.backBtn];
+    
+    self.passwordImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"CDocumentPasswordImagePassword" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil]];
+    [self.view addSubview:self.passwordImageView];
+    
+    self.titleLablel = [[UILabel alloc] init];
+    self.titleLablel.text = NSLocalizedString(@"Please Enter The Password", nil);
+    self.titleLablel.adjustsFontSizeToFitWidth = YES;
+    [self.view addSubview:self.titleLablel];
+    
+    self.enterView = [[UIView alloc] init];
+    [self.view addSubview:self.enterView];
+    [self initEnterView];
+    
+    self.warningLabel = [[UILabel alloc] init];
+    self.warningLabel.text = NSLocalizedString(@"Wrong Password", nil);
+    self.warningLabel.textColor = [UIColor redColor];
+    [self.view addSubview:self.warningLabel];
+    self.warningLabel.hidden = YES;
+
+    self.OKBtn = [UIButton buttonWithType:UIButtonTypeCustom];
+    [self.OKBtn setTitle:NSLocalizedString(@"Done", nil) forState:UIControlStateNormal];
+    [self.OKBtn addTarget:self action:@selector(buttonItemClicked_ok:) forControlEvents:UIControlEventTouchUpInside];
+    [self.OKBtn setTitleColor:[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0] forState:UIControlStateNormal];
+    self.OKBtn.backgroundColor = [UIColor colorWithRed:221.0/255.0 green:233.0/255.0 blue:255.0/255.0 alpha:1.0];
+    [self.view addSubview:self.OKBtn];
+    
+    self.view.backgroundColor = [CPDFColorUtils CPDFViewControllerBackgroundColor];
+}
+
+- (void)viewWillLayoutSubviews {
+    if (@available(iOS 11.0, *)) {
+        self.backBtn.frame = CGRectMake(self.view.frame.size.width - self.view.safeAreaInsets.right - 70, self.view.safeAreaInsets.top, 50, 50);
+        self.passwordImageView.frame = CGRectMake((self.view.frame.size.width - 100)/2, CGRectGetMaxY(self.backBtn.frame), 100, 100);
+        self.titleLablel.frame = CGRectMake((self.view.frame.size.width - 200)/2, CGRectGetMaxY(self.passwordImageView.frame), 200, 50);
+        self.enterView.frame = CGRectMake((self.view.frame.size.width - 300)/2, CGRectGetMaxY(self.titleLablel.frame), 300, 60);
+        self.warningLabel.frame = CGRectMake((self.view.frame.size.width - 300)/2, CGRectGetMaxY(self.enterView.frame), 300, 40);
+        self.OKBtn.frame = CGRectMake((self.view.frame.size.width - 300)/2, CGRectGetMaxY(self.warningLabel.frame), 300, 60);
+    } else {
+        self.backBtn.frame = CGRectMake(self.view.frame.size.width - 60, 65, 50, 50);
+        self.passwordImageView.frame = CGRectMake((self.view.frame.size.width - 100)/2, CGRectGetMaxY(self.backBtn.frame), 100, 100);
+        self.titleLablel.frame = CGRectMake((self.view.frame.size.width - 100)/2, CGRectGetMaxY(self.passwordImageView.frame), 200, 50);
+        self.enterView.frame = CGRectMake((self.view.frame.size.width - 300)/2, CGRectGetMaxY( self.titleLablel.frame), 300, 60);
+        self.warningLabel.frame = CGRectMake((self.view.frame.size.width - 300)/2, CGRectGetMaxY(self.enterView.frame), 300, 40);
+        self.OKBtn.frame = CGRectMake((self.view.frame.size.width - 300)/2, CGRectGetMaxY(self.warningLabel.frame), 300, 60);
+    }
+    self.passLabel.frame = CGRectMake(0, 0, 80, self.enterView.frame.size.height-1);
+    self.enterTextField.frame = CGRectMake(80, 0, self.enterView.frame.size.width-80, self.enterView.frame.size.height-1);
+    self.splitVidew.frame = CGRectMake(0, self.enterView.frame.size.height-1, self.enterView.frame.size.width, 1);
+    self.clearButton.frame = CGRectMake(self.enterView.frame.size.width-30, (self.enterView.frame.size.height-24)/2, 24, 24);
+}
+
+#pragma mark - Private Methods
+
+- (void)initEnterView {
+    self.passLabel = [[UILabel alloc] init];
+    self.passLabel.text = NSLocalizedString(@"Password", nil);
+    [self.enterView addSubview:self.passLabel];
+    
+    self.enterTextField = [[UITextField alloc] init];
+    self.enterTextField.borderStyle = UITextBorderStyleNone;
+    self.enterTextField.secureTextEntry = YES;
+    self.enterTextField.delegate = self;
+    self.enterTextField.font = [UIFont systemFontOfSize:13];
+    self.enterTextField.returnKeyType = UIReturnKeyDone;
+    self.enterTextField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 8, 0)];
+    self.enterTextField.leftViewMode = UITextFieldViewModeAlways;
+    self.enterTextField.rightView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 8, 0)];
+    self.enterTextField.rightViewMode = UITextFieldViewModeAlways;
+    self.enterTextField.placeholder = NSLocalizedString(@"Please enter the password", nil);
+    [self.enterTextField becomeFirstResponder];
+    [self.enterTextField addTarget:self action:@selector(textField_change:) forControlEvents:UIControlEventEditingChanged];
+    [self.enterView addSubview:self.enterTextField];
+    
+    self.clearButton = [UIButton buttonWithType:UIButtonTypeCustom];
+    self.clearButton.layer.cornerRadius = 12;
+    self.clearButton.layer.masksToBounds = YES;
+    [self.clearButton setImage:[UIImage imageNamed:@"CDocumentPasswordImageClear" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
+    [self.clearButton addTarget:self action:@selector(buttonItemClicked_clear:) forControlEvents:UIControlEventTouchUpInside];
+    [self.enterView addSubview:self.clearButton];
+    self.clearButton.hidden = YES;
+    
+    self.splitVidew = [[UIView alloc] init];
+    self.splitVidew.backgroundColor = [CPDFColorUtils CTableviewCellSplitColor];
+    [self.enterView addSubview:self.splitVidew];
+}
+
+#pragma mark - Action
+
+- (void)buttonItemClicked_back:(UIButton *)button {
+    [self dismissViewControllerAnimated:YES completion:^{
+        if (self.delegate && [self.delegate respondsToSelector:@selector(documentPasswordViewControllerCancel:)]) {
+            [self.delegate documentPasswordViewControllerCancel:self];
+        }
+    }];
+}
+
+- (void)buttonItemClicked_ok:(UIButton *)button {
+    if ([self.document unlockWithPassword:self.enterTextField.text]) {
+        [self dismissViewControllerAnimated:YES completion:^{
+            if (self.delegate && [self.delegate respondsToSelector:@selector(documentPasswordViewControllerOpen:)]) {
+                [self.delegate documentPasswordViewControllerOpen:self];
+            }
+        }];
+    } else {
+        self.warningLabel.hidden = NO;
+    }
+}
+
+- (void)buttonItemClicked_clear:(UIButton *)button {
+    self.OKBtn.backgroundColor = [UIColor colorWithRed:221.0/255.0 green:233.0/255.0 blue:255.0/255.0 alpha:1.0];
+    self.warningLabel.hidden = YES;
+    self.enterTextField.text = @"";
+    self.clearButton.hidden = YES;
+}
+
+- (void)textField_change:(UITextField *)sender {
+    if ([sender.text length] == 0) {
+        self.OKBtn.backgroundColor = [UIColor colorWithRed:221.0/255.0 green:233.0/255.0 blue:255.0/255.0 alpha:1.0];
+        self.warningLabel.hidden = YES;
+        self.clearButton.hidden = YES;
+    } else {
+        self.OKBtn.backgroundColor = [UIColor blueColor];
+        self.clearButton.hidden = NO;
+    }
+}
+
+#pragma mark - UITextFieldDelegate
+
+- (BOOL)textFieldShouldReturn:(UITextField *)textField {
+    [textField resignFirstResponder];
+    return YES;
+}
+
+- (BOOL)textFieldShouldClear:(UITextField *)textField {
+    self.OKBtn.backgroundColor = [UIColor colorWithRed:221.0/255.0 green:233.0/255.0 blue:255.0/255.0 alpha:1.0];
+    self.warningLabel.hidden = YES;
+    return YES;
+}
+
+@end

+ 12 - 0
compdfkit-tools/compdfkit-tools/Common/Utils/Image.xcassets/CDocumentPasswordImageBack.imageset/Contents.json

@@ -0,0 +1,12 @@
+{
+  "images" : [
+    {
+      "filename" : "close.pdf",
+      "idiom" : "universal"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

+ 87 - 0
compdfkit-tools/compdfkit-tools/Common/Utils/Image.xcassets/CDocumentPasswordImageBack.imageset/close.pdf

@@ -0,0 +1,87 @@
+%PDF-1.7
+
+1 0 obj
+  << >>
+endobj
+
+2 0 obj
+  << /Length 3 0 R >>
+stream
+/DeviceRGB CS
+/DeviceRGB cs
+q
+0.707107 0.707107 -0.707107 0.707107 14.853499 -5.813704 cm
+0.262745 0.278431 0.301961 scn
+6.999999 7.170288 m
+6.999999 6.420288 l
+8.500000 6.420288 l
+8.500000 7.170288 l
+8.500000 13.420261 l
+14.750000 13.420261 l
+15.500000 13.420261 l
+15.500000 14.920261 l
+14.750000 14.920261 l
+8.500000 14.920261 l
+8.500000 21.170288 l
+8.500000 21.920288 l
+6.999999 21.920288 l
+6.999999 21.170288 l
+6.999999 14.920261 l
+0.750000 14.920261 l
+0.000000 14.920261 l
+0.000000 13.420261 l
+0.750000 13.420261 l
+6.999999 13.420261 l
+6.999999 7.170288 l
+h
+f*
+n
+Q
+
+endstream
+endobj
+
+3 0 obj
+  570
+endobj
+
+4 0 obj
+  << /Annots []
+     /Type /Page
+     /MediaBox [ 0.000000 0.000000 20.000000 20.000000 ]
+     /Resources 1 0 R
+     /Contents 2 0 R
+     /Parent 5 0 R
+  >>
+endobj
+
+5 0 obj
+  << /Kids [ 4 0 R ]
+     /Count 1
+     /Type /Pages
+  >>
+endobj
+
+6 0 obj
+  << /Pages 5 0 R
+     /Type /Catalog
+  >>
+endobj
+
+xref
+0 7
+0000000000 65535 f
+0000000010 00000 n
+0000000034 00000 n
+0000000660 00000 n
+0000000682 00000 n
+0000000855 00000 n
+0000000929 00000 n
+trailer
+<< /ID [ (some) (id) ]
+   /Root 6 0 R
+   /Size 7
+>>
+startxref
+988
+%%EOF

+ 12 - 0
compdfkit-tools/compdfkit-tools/Common/Utils/Image.xcassets/CDocumentPasswordImageClear.imageset/Contents.json

@@ -0,0 +1,12 @@
+{
+  "images" : [
+    {
+      "filename" : "close.pdf",
+      "idiom" : "universal"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

+ 91 - 0
compdfkit-tools/compdfkit-tools/Common/Utils/Image.xcassets/CDocumentPasswordImageClear.imageset/close.pdf

@@ -0,0 +1,91 @@
+%PDF-1.7
+
+1 0 obj
+  << >>
+endobj
+
+2 0 obj
+  << /Length 3 0 R >>
+stream
+/DeviceRGB CS
+/DeviceRGB cs
+q
+1.000000 0.000000 -0.000000 1.000000 1.000000 1.000000 cm
+0.600000 0.600000 0.600000 scn
+18.000000 9.000000 m
+18.000000 4.029437 13.970563 0.000000 9.000000 0.000000 c
+4.029437 0.000000 0.000000 4.029437 0.000000 9.000000 c
+0.000000 13.970563 4.029437 18.000000 9.000000 18.000000 c
+13.970563 18.000000 18.000000 13.970563 18.000000 9.000000 c
+h
+f
+n
+Q
+q
+0.707107 0.707107 -0.707107 0.707107 13.749959 -2.499959 cm
+1.000000 1.000000 1.000000 scn
+6.874927 12.052552 m
+6.874927 17.677612 l
+5.624927 17.677612 l
+5.624927 12.052552 l
+0.000000 12.052552 l
+0.000000 10.802552 l
+5.624927 10.802552 l
+5.624927 5.177612 l
+6.874927 5.177612 l
+6.874927 10.802552 l
+12.500000 10.802552 l
+12.500000 12.052552 l
+6.874927 12.052552 l
+h
+f*
+n
+Q
+
+endstream
+endobj
+
+3 0 obj
+  757
+endobj
+
+4 0 obj
+  << /Annots []
+     /Type /Page
+     /MediaBox [ 0.000000 0.000000 20.000000 20.000000 ]
+     /Resources 1 0 R
+     /Contents 2 0 R
+     /Parent 5 0 R
+  >>
+endobj
+
+5 0 obj
+  << /Kids [ 4 0 R ]
+     /Count 1
+     /Type /Pages
+  >>
+endobj
+
+6 0 obj
+  << /Pages 5 0 R
+     /Type /Catalog
+  >>
+endobj
+
+xref
+0 7
+0000000000 65535 f
+0000000010 00000 n
+0000000034 00000 n
+0000000847 00000 n
+0000000869 00000 n
+0000001042 00000 n
+0000001116 00000 n
+trailer
+<< /ID [ (some) (id) ]
+   /Root 6 0 R
+   /Size 7
+>>
+startxref
+1175
+%%EOF

+ 12 - 0
compdfkit-tools/compdfkit-tools/Common/Utils/Image.xcassets/CDocumentPasswordImagePassword.imageset/Contents.json

@@ -0,0 +1,12 @@
+{
+  "images" : [
+    {
+      "filename" : "pic_password.pdf",
+      "idiom" : "universal"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

+ 235 - 0
compdfkit-tools/compdfkit-tools/Common/Utils/Image.xcassets/CDocumentPasswordImagePassword.imageset/pic_password.pdf

@@ -0,0 +1,235 @@
+%PDF-1.7
+
+1 0 obj
+  << >>
+endobj
+
+2 0 obj
+  << /Length 3 0 R >>
+stream
+/DeviceRGB CS
+/DeviceRGB cs
+q
+1.000000 0.000000 -0.000000 1.000000 0.000000 4.000000 cm
+0.942017 0.942017 0.942017 scn
+53.000000 46.020203 m
+53.000000 2.707069 l
+53.000000 1.211998 51.798538 0.000000 50.316456 0.000000 c
+2.683544 0.000000 l
+1.201464 0.000000 0.000000 1.211998 0.000000 2.707069 c
+0.000000 64.292931 l
+0.000000 65.788002 1.201464 67.000000 2.683544 67.000000 c
+33.544304 67.000000 l
+53.000000 46.020203 l
+h
+f*
+n
+Q
+q
+1.000000 0.000000 -0.000000 1.000000 6.000000 20.000000 cm
+1.000000 1.000000 1.000000 scn
+0.000000 38.560001 m
+0.000000 39.355289 0.644710 40.000000 1.440000 40.000000 c
+12.559999 40.000000 l
+13.355289 40.000000 14.000000 39.355289 14.000000 38.560001 c
+14.000000 37.439999 l
+14.000000 36.644711 13.355290 36.000000 12.559999 36.000000 c
+1.440000 36.000000 l
+0.644710 36.000000 0.000000 36.644711 0.000000 37.439999 c
+0.000000 38.560001 l
+h
+20.000000 38.559998 m
+20.000000 39.355289 20.644711 40.000000 21.440001 40.000000 c
+34.559998 40.000000 l
+35.355289 40.000000 36.000000 39.355289 36.000000 38.560001 c
+36.000000 30.440001 l
+36.000000 29.644711 35.355289 29.000000 34.560001 29.000000 c
+21.440001 29.000000 l
+20.644711 29.000000 20.000000 29.644711 20.000000 30.440001 c
+20.000000 38.559998 l
+h
+1.440000 33.000000 m
+0.644710 33.000000 0.000000 32.355289 0.000000 31.559999 c
+0.000000 30.440001 l
+0.000000 29.644711 0.644710 29.000000 1.440000 29.000000 c
+12.559999 29.000000 l
+13.355290 29.000000 14.000000 29.644711 14.000000 30.440001 c
+14.000000 31.559999 l
+14.000000 32.355289 13.355289 33.000000 12.559999 33.000000 c
+1.440000 33.000000 l
+h
+0.000000 23.559999 m
+0.000000 24.355289 0.644710 25.000000 1.440000 25.000000 c
+38.560001 25.000000 l
+39.355293 25.000000 40.000000 24.355289 40.000000 23.559999 c
+40.000000 22.440001 l
+40.000000 21.644711 39.355289 21.000000 38.560001 21.000000 c
+1.439998 21.000000 l
+0.644708 21.000000 0.000000 21.644711 0.000000 22.440001 c
+0.000000 23.559999 l
+h
+1.440000 18.000000 m
+0.644710 18.000000 0.000000 17.355289 0.000000 16.559999 c
+0.000000 15.440001 l
+0.000000 14.644711 0.644708 14.000000 1.439998 14.000000 c
+38.560001 14.000000 l
+39.355289 14.000000 40.000000 14.644711 40.000000 15.440001 c
+40.000000 16.559999 l
+40.000000 17.355289 39.355293 18.000000 38.560001 18.000000 c
+1.440000 18.000000 l
+h
+0.000000 9.559999 m
+0.000000 10.355289 0.644710 11.000000 1.440000 11.000000 c
+38.560001 11.000000 l
+39.355293 11.000000 40.000000 10.355289 40.000000 9.559999 c
+40.000000 8.440001 l
+40.000000 7.644711 39.355289 7.000000 38.560001 7.000000 c
+1.439998 7.000000 l
+0.644708 7.000000 0.000000 7.644711 0.000000 8.440001 c
+0.000000 9.559999 l
+h
+1.440000 4.000000 m
+0.644710 4.000000 0.000000 3.355289 0.000000 2.560001 c
+0.000000 1.439999 l
+0.000000 0.644711 0.644708 0.000000 1.439998 0.000000 c
+38.560001 0.000000 l
+39.355289 0.000000 40.000000 0.644711 40.000000 1.439999 c
+40.000000 2.560001 l
+40.000000 3.355289 39.355293 4.000000 38.560001 4.000000 c
+1.440000 4.000000 l
+h
+f*
+n
+Q
+q
+1.000000 0.000000 -0.000000 1.000000 37.000000 0.000000 cm
+1.000000 0.674510 0.152941 scn
+4.800000 22.222221 m
+2.160000 22.222221 l
+0.967065 22.222221 0.000000 21.255157 0.000000 20.062222 c
+0.000000 2.160000 l
+0.000000 0.967068 0.967065 0.000000 2.160000 0.000000 c
+29.840000 0.000000 l
+31.032934 0.000000 32.000000 0.967064 32.000000 2.160000 c
+32.000000 20.062222 l
+32.000000 21.255157 31.032936 22.222221 29.840000 22.222221 c
+27.200001 22.222221 l
+27.200001 23.333332 l
+27.200001 29.776655 22.185589 35.000000 16.000000 35.000000 c
+9.814411 35.000000 4.800000 29.776655 4.800000 23.333332 c
+4.800000 22.222221 l
+h
+8.000000 22.222221 m
+24.000000 22.222221 l
+24.000000 23.333332 l
+24.000000 27.935707 20.418278 31.666666 16.000000 31.666666 c
+11.581722 31.666666 8.000000 27.935707 8.000000 23.333332 c
+8.000000 22.222221 l
+h
+f*
+n
+Q
+q
+1.000000 0.000000 -0.000000 1.000000 37.000000 0.000000 cm
+1.000000 0.611765 0.098039 scn
+4.800000 22.222221 m
+2.160000 22.222221 l
+0.967065 22.222221 0.000000 21.255157 0.000000 20.062222 c
+0.000000 2.160000 l
+0.000000 0.967068 0.967065 0.000000 2.160000 0.000000 c
+29.840000 0.000000 l
+31.032934 0.000000 32.000000 0.967064 32.000000 2.160000 c
+32.000000 20.062222 l
+32.000000 21.255157 31.032936 22.222221 29.840000 22.222221 c
+27.200001 22.222221 l
+27.200001 23.333332 l
+27.200001 29.776655 22.185589 35.000000 16.000000 35.000000 c
+9.814411 35.000000 4.800000 29.776655 4.800000 23.333332 c
+4.800000 22.222221 l
+h
+8.000000 22.222221 m
+24.000000 22.222221 l
+24.000000 23.333332 l
+24.000000 27.935707 20.418278 31.666666 16.000000 31.666666 c
+11.581722 31.666666 8.000000 27.935707 8.000000 23.333332 c
+8.000000 22.222221 l
+h
+f*
+n
+Q
+q
+1.000000 0.000000 -0.000000 1.000000 50.516113 5.479675 cm
+0.942017 0.942017 0.942017 scn
+4.622559 3.704224 m
+6.004941 4.172025 7.000000 5.479970 7.000000 7.020325 c
+7.000000 8.953321 5.432997 10.520325 3.500000 10.520325 c
+1.567003 10.520325 0.000000 8.953321 0.000000 7.020325 c
+0.000000 5.390345 1.114224 4.020605 2.622559 3.631219 c
+2.622559 1.000000 l
+2.622559 0.447715 3.070274 0.000000 3.622559 0.000000 c
+4.174843 0.000000 4.622559 0.447715 4.622559 1.000000 c
+4.622559 3.704224 l
+h
+f*
+n
+Q
+q
+1.000000 0.000000 -0.000000 1.000000 33.543945 50.020203 cm
+0.867647 0.867647 0.867647 scn
+0.000000 20.979797 m
+19.455696 0.000000 l
+2.000000 0.000000 l
+0.895431 0.000000 0.000000 0.895430 0.000000 2.000000 c
+0.000000 20.979797 l
+h
+f*
+n
+Q
+
+endstream
+endobj
+
+3 0 obj
+  5384
+endobj
+
+4 0 obj
+  << /Annots []
+     /Type /Page
+     /MediaBox [ 0.000000 0.000000 69.000000 71.000000 ]
+     /Resources 1 0 R
+     /Contents 2 0 R
+     /Parent 5 0 R
+  >>
+endobj
+
+5 0 obj
+  << /Kids [ 4 0 R ]
+     /Count 1
+     /Type /Pages
+  >>
+endobj
+
+6 0 obj
+  << /Pages 5 0 R
+     /Type /Catalog
+  >>
+endobj
+
+xref
+0 7
+0000000000 65535 f
+0000000010 00000 n
+0000000034 00000 n
+0000005474 00000 n
+0000005497 00000 n
+0000005670 00000 n
+0000005744 00000 n
+trailer
+<< /ID [ (some) (id) ]
+   /Root 6 0 R
+   /Size 7
+>>
+startxref
+5803
+%%EOF

+ 6 - 0
compdfkit-tools/compdfkit-tools/Common/Utils/Image.xcassets/Contents.json

@@ -0,0 +1,6 @@
+{
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

+ 50 - 25
compdfkit-tools/compdfkit-tools/PageEdit/Control/CPDFPageEditViewController.m

@@ -211,6 +211,7 @@
         NSInteger count = [self.collectionView indexPathsForSelectedItems].count;
         self.titleLabel.text = [NSString stringWithFormat:@"%@ %ld",NSLocalizedString(@"Selected:", nil), (long)count];
         self.pageEditToolBar.isSelect = [self getIsSelect];
+        self.pageEditToolBar.currentPageIndex = [self getMaxSelectIndex];
     } else {
         self.titleLabel.text = NSLocalizedString(@"Page Edit", nil);
     }
@@ -270,6 +271,7 @@
         case UIGestureRecognizerStateEnded:
         {
             [self.collectionView endInteractiveMovement];
+            [self.collectionView reloadData];
         }
             break;
         default:
@@ -308,7 +310,10 @@
     if (sourceIndexPath.item != destinationIndexPath.item) {
         [self.pdfView.document movePageAtIndex:sourceIndexPath.item withPageAtIndex:destinationIndexPath.item];
         self.isPageEdit = YES;
+        [self updateTitle];
+        [collectionView reloadData];
     }
+    
 }
 
 #pragma mark - UICollectionViewDelegate
@@ -359,24 +364,26 @@
     [self.collectionView reloadData];
     [self.pageEditToolBar reloadData];
     
-    [self updateTitle];
-    self.isPageEdit = YES;
     NSIndexPath *indexPath = [NSIndexPath indexPathForItem:pageIndex inSection:0];
     [self.collectionView selectItemAtIndexPath:indexPath
                                       animated:NO
                                 scrollPosition:UICollectionViewScrollPositionCenteredVertically];
+    [self updateTitle];
+    self.isPageEdit = YES;
 }
 
 - (void)pageEditToolBarPDFInsert:(CPageEditToolBar *)pageEditToolBar pageModel:(CBlankPageModel *)pageModel document:(nonnull CPDFDocument *)document {
     [self.pdfView.document importPages:pageModel.indexSet fromDocument:document atIndex:pageModel.pageIndex];
     [self.collectionView reloadData];
     
-    [pageModel.indexSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
-        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:idx+1 inSection:0];
+    for (int i = 0; i < pageModel.indexSet.count; i++) {
+        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i+pageModel.pageIndex inSection:0];
         [self.collectionView selectItemAtIndexPath:indexPath
                                           animated:NO
                                     scrollPosition:UICollectionViewScrollPositionCenteredVertically];
-    }];
+    }
+    [self updateTitle];
+    self.isPageEdit = YES;
 }
 
 - (void)pageEditToolBarExtract:(CPageEditToolBar *)pageEditToolBar {
@@ -392,15 +399,18 @@
     [document importPages:indexSet fromDocument:self.pdfView.document atIndex:0];
     [document writeToURL:[NSURL fileURLWithPath:filePath]];
     
-    NSString *message = [NSString stringWithFormat:NSLocalizedString(@"This file has been saved in:'Documents/'", nil)];
-    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
-                                                           style:UIAlertActionStyleCancel
-                                                         handler:nil];
-    UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Successfully!", nil)
-                                                                   message:message
-                                                            preferredStyle:UIAlertControllerStyleAlert];
-    [alert addAction:cancelAction];
-    [self presentViewController:alert animated:YES completion:nil];
+    UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:@[self.pdfView.document.documentURL] applicationActivities:nil];
+        activityVC.definesPresentationContext = YES;
+        [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!");
+            }
+        };
+    
     [self.pageEditToolBar reloadData];
     
     self.isPageEdit = YES;
@@ -409,22 +419,23 @@
 
 - (void)pageEditToolBarRotate:(CPageEditToolBar *)pageEditToolBar {
     NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
-    for (NSIndexPath *indexPath in [self.collectionView indexPathsForSelectedItems]) {
+    NSArray<NSIndexPath *> *indexPathsForSelectedItems = [self.collectionView indexPathsForSelectedItems];
+    for (NSIndexPath *indexPath in indexPathsForSelectedItems) {
         CPDFPageEditViewCell *cell = (CPDFPageEditViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
-        cell.imageView.transform = CGAffineTransformRotate(cell.imageView.transform, M_PI/2);
-        [indexSet addIndex:indexPath.item];
-        
+//        cell.imageView.transform = CGAffineTransformRotate(cell.imageView.transform, M_PI/2);
+//        [indexSet addIndex:indexPath.item];
+//
         CPDFPage *pPage = [self.pdfView.document pageAtIndex:indexPath.item];
         pPage.rotation += 90;
-        
-        CGSize pageSize = [self.pdfView.document pageSizeAtIndex:indexPath.item];
-        CGFloat multiple = MAX(pageSize.width / 110, pageSize.height / 173);
-        
-        cell.imageSize = CGSizeMake(pageSize.width / multiple, pageSize.height / multiple);
-        [cell setNeedsLayout];
+        if (pPage.rotation == 360) {
+            pPage.rotation = 0;
+        }
+        [self.collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
+        [self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
+;
     }
-    
     [self updateTitle];
+    [self.pageEditToolBar reloadData];
     self.isPageEdit = YES;
 }
 
@@ -473,6 +484,13 @@
     [self.collectionView reloadData];
     [self.pageEditToolBar reloadData];
     
+    for (int i = 0; i < document.pageCount; i++) {
+        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i+min inSection:0];
+        [self.collectionView selectItemAtIndexPath:indexPath
+                                          animated:NO
+                                    scrollPosition:UICollectionViewScrollPositionCenteredVertically];
+    }
+    
     [self updateTitle];
     self.isPageEdit = YES;
 }
@@ -488,6 +506,13 @@
     [self.collectionView reloadData];
     [self.pageEditToolBar reloadData];
     
+    for (int i = 0; i < indexSet.count; i++) {
+        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i+max inSection:0];
+        [self.collectionView selectItemAtIndexPath:indexPath
+                                          animated:NO
+                                    scrollPosition:UICollectionViewScrollPositionCenteredVertically];
+    }
+    
     [self updateTitle];
     self.isPageEdit = YES;
 }

+ 52 - 55
compdfkit-tools/compdfkit-tools/PageEdit/Views/CPageEditToolBar.m

@@ -14,10 +14,11 @@
 #import "CPDFPDFInsertViewController.h"
 #import "CActivityIndicatorView.h"
 #import "AAPLCustomPresentationController.h"
+#import "CDocumentPasswordViewController.h"
 
 #import <ComPDFKit/ComPDFKit.h>
 
-@interface CPageEditToolBar () <UIDocumentPickerDelegate, CPDFPageInsertViewControllerDelegate, CPDFPDFInsertViewControllerDelegate>
+@interface CPageEditToolBar () <UIDocumentPickerDelegate, CPDFPageInsertViewControllerDelegate, CPDFPDFInsertViewControllerDelegate, CDocumentPasswordViewControllerDelegate>
 
 @property (nonatomic, strong) UIScrollView *scrollView;
 
@@ -212,46 +213,6 @@
     [tRootViewControl presentViewController:alert animated:YES completion:nil];
 }
 
-- (void)reloadDocumentWithFilePath:(NSString *)filePath password:(nullable NSString *)password completion:(void (^)(BOOL result))completion {
-    if (![self.loadingView superview]) {
-        [self addSubview:self.loadingView];
-    }
-    [self.loadingView startAnimating];
-    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-        NSURL *url = [NSURL fileURLWithPath:filePath];
-        CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];
-        if([document isLocked]) {
-            [document unlockWithPassword:password];
-        }
-        dispatch_async(dispatch_get_main_queue(), ^{
-            [self.loadingView stopAnimating];
-            [self.loadingView removeFromSuperview];
-            if (document.error && document.error.code != CPDFDocumentPasswordError) {
-                UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-                }];
-                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@""
-                                                                               message:NSLocalizedString(@"Sorry PDF Reader Can't open this pdf file!", nil)
-                                                                        preferredStyle:UIAlertControllerStyleAlert];
-                [alert addAction:okAction];
-                if (completion) {
-                    completion(NO);
-                }
-            } else {
-                if (self.selectedIndex == CPageEditToolBarInsert) {
-                    self.insertDocument = document;
-                } else if (self.selectedIndex == CPageEditToolBarReplace) {
-                    self.replaceDocument = document;
-                }
-                
-                [self handleDocument];
-                if (completion) {
-                    completion(YES);
-                }
-            }
-        });
-    });
-}
-
 #pragma mark - Action
 
 - (void)buttonItemClicked_switch:(UIButton *)button {
@@ -260,16 +221,7 @@
         UIButton *selectedButton = [self.pageEditBtns objectAtIndex:self.selectedIndex];
         selectedButton.backgroundColor = [UIColor clearColor];
     }
-    if (button.tag != self.selectedIndex) {
-        button.backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
-        self.selectedIndex = button.tag;
-    } else {
-        self.selectedIndex = -1;
-        if (button.tag == CPageEditToolBarRotate) {
-            self.selectedIndex = button.tag;
-            button.backgroundColor = [CPDFColorUtils CAnnotationBarSelectBackgroundColor];
-        }
-    }
+    self.selectedIndex = button.tag;
     
     switch (button.tag) {
         case CPageEditToolBarInsert:
@@ -365,7 +317,6 @@
 #pragma mark - UIDocumentPickerDelegate
 
 - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls{
-    __weak typeof(self) weakSelf = self;
     BOOL fileUrlAuthozied = [urls.firstObject startAccessingSecurityScopedResource];
     if(fileUrlAuthozied){
         NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
@@ -382,10 +333,44 @@
                [[NSFileManager defaultManager] copyItemAtPath:newURL.path toPath:documentPath error:NULL];
 
             }
+            NSURL *url = [NSURL fileURLWithPath:documentPath];
+            CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];
+            
+            if (self.selectedIndex == CPageEditToolBarInsert) {
+                self.insertDocument = document;
+            } else if (self.selectedIndex == CPageEditToolBarReplace) {
+                self.replaceDocument = document;
+            }
+            
+            if (document.error && document.error.code != CPDFDocumentPasswordError) {
+                UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+                }];
+                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@""
+                                                                               message:NSLocalizedString(@"Sorry PDF Reader Can't open this pdf file!", nil)
+                                                                        preferredStyle:UIAlertControllerStyleAlert];
+                [alert addAction:okAction];
+                UIViewController *tRootViewControl = [UIApplication sharedApplication].keyWindow.rootViewController;
+                if ([tRootViewControl presentedViewController]) {
+                    tRootViewControl = [tRootViewControl presentedViewController];
+                }
+                [tRootViewControl presentViewController:alert animated:YES completion:nil];
+            } else {
+                if([document isLocked]) {
+                    CDocumentPasswordViewController *documentPasswordVC = [[CDocumentPasswordViewController alloc] initWithDocument:document];
+                    documentPasswordVC.delegate = self;
+                    documentPasswordVC.modalPresentationStyle = UIModalPresentationFullScreen;
+                    
+                    UIViewController *tRootViewControl = [UIApplication sharedApplication].keyWindow.rootViewController;
+                    if ([tRootViewControl presentedViewController]) {
+                        tRootViewControl = [tRootViewControl presentedViewController];
+                    }
+                    [tRootViewControl presentViewController:documentPasswordVC animated:YES completion:nil];
+                } else {
+                    [self handleDocument];
+                }
+                
+            }
             
-            [weakSelf reloadDocumentWithFilePath:documentPath password:nil completion:^(BOOL result) {
-            }];
-
         }];
         [urls.firstObject stopAccessingSecurityScopedResource];
     }
@@ -395,4 +380,16 @@
     [self reloadData];
 }
 
+#pragma mark - CDocumentPasswordViewControllerDelegate
+
+- (void)documentPasswordViewControllerOpen:(CDocumentPasswordViewController *)documentPasswordViewController {
+
+    [self handleDocument];
+    [self reloadData];
+}
+
+- (void)documentPasswordViewControllerCancel:(CDocumentPasswordViewController *)documentPasswordViewController {
+    [self reloadData];
+}
+
 @end