|
@@ -256,6 +256,65 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+- (NSString *)fileNameWithSelectedPages {
|
|
|
+ NSArray * selectPages = [self selectedPages];
|
|
|
+ NSString *fileName = nil;
|
|
|
+ if (selectPages.count > 0) {
|
|
|
+ if (selectPages.count == 1) {
|
|
|
+ NSInteger idx = [self.pdfView.document indexForPage:selectPages.firstObject] + 1;
|
|
|
+ return [NSString stringWithFormat:@"%ld",idx];
|
|
|
+ }
|
|
|
+
|
|
|
+ NSMutableSet *sortIndex = [NSMutableSet set];
|
|
|
+ for (CPDFPage * page in selectPages) {
|
|
|
+ NSInteger idx = [self.pdfView.document indexForPage:page] + 1;
|
|
|
+ [sortIndex addObject:@(idx)];
|
|
|
+ }
|
|
|
+ NSSortDescriptor * sort = [[NSSortDescriptor alloc] initWithKey:nil ascending:YES];
|
|
|
+ NSArray *sortDesc = @[sort];
|
|
|
+ NSArray *sortArray = [sortIndex sortedArrayUsingDescriptors:sortDesc];
|
|
|
+
|
|
|
+ NSInteger a = 0;
|
|
|
+ NSInteger b = 0;
|
|
|
+
|
|
|
+ for (NSNumber *num in sortArray) {
|
|
|
+ if (fileName) {
|
|
|
+ if (num.integerValue == b+1) {
|
|
|
+ b = num.integerValue;
|
|
|
+ if (num == sortArray.lastObject) {
|
|
|
+ fileName = [fileName stringByAppendingString:[NSString stringWithFormat:@"%ld-%ld",a,b]];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (a == b) {
|
|
|
+ fileName = [fileName stringByAppendingString:[NSString stringWithFormat:@"%ld,",a]];
|
|
|
+ } else {
|
|
|
+ fileName = [fileName stringByAppendingString:[NSString stringWithFormat:@"%ld-%ld,",a,b]];
|
|
|
+ }
|
|
|
+ a = b = num.integerValue;
|
|
|
+ if (num == sortArray.lastObject) {
|
|
|
+ fileName = [fileName stringByAppendingString:[NSString stringWithFormat:@"%ld",a]];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ fileName = @"";
|
|
|
+ a = b = num.integerValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return fileName;
|
|
|
+ }
|
|
|
+ return @"";
|
|
|
+}
|
|
|
+
|
|
|
+- (NSArray<CPDFPage *> *)selectedPages {
|
|
|
+ NSMutableArray *pages = [NSMutableArray array];
|
|
|
+ [[self.collectionView indexPathsForSelectedItems] enumerateObjectsUsingBlock:^(NSIndexPath * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
+ if (idx < self.pdfView.document.pageCount) {
|
|
|
+ [pages addObject:[self.pdfView.document pageAtIndex:obj.item]];
|
|
|
+ }
|
|
|
+ }];
|
|
|
+ return pages;
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - GestureRecognized
|
|
|
|
|
|
- (void)longPressGestureRecognized:(UILongPressGestureRecognizer *)gestureRecognizer {
|
|
@@ -396,7 +455,7 @@
|
|
|
- (void)pageEditToolBarExtract:(CPageEditToolBar *)pageEditToolBar {
|
|
|
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
|
|
|
NSString *fileName = self.pdfView.document.documentURL.lastPathComponent.stringByDeletingPathExtension;
|
|
|
- NSString *filePath = [NSString stringWithFormat:@"%@/%@_Pages.pdf",path,fileName];
|
|
|
+ NSString *filePath = [NSString stringWithFormat:@"%@/%@_%@.pdf",path,fileName,[self fileNameWithSelectedPages]];
|
|
|
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
|
|
|
for (NSIndexPath *indexPath in [self.collectionView indexPathsForSelectedItems]) {
|
|
|
[indexSet addIndex:indexPath.item];
|
|
@@ -412,16 +471,16 @@
|
|
|
activityVC.popoverPresentationController.sourceView = (UIButton *)self.pageEditToolBar.pageEditBtns[2];
|
|
|
activityVC.popoverPresentationController.sourceRect = ((UIButton *)self.pageEditToolBar.pageEditBtns[2]).bounds;
|
|
|
}
|
|
|
- [self presentViewController:activityVC animated:YES completion:nil];
|
|
|
- activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
|
|
|
+ [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!");
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
- if (completed) {
|
|
|
- NSLog(@"Success!");
|
|
|
- } else {
|
|
|
- NSLog(@"Failed Or Canceled!");
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
[self.pageEditToolBar reloadData];
|
|
|
|
|
|
self.isPageEdit = YES;
|