Ver código fonte

PDFSamples(iOS)- PDFPage samples 的完成

yangliuhua 1 ano atrás
pai
commit
251c27536a

+ 14 - 0
Samples/Samples.xcodeproj/project.pbxproj

@@ -23,6 +23,7 @@
 		C97699752A569AA400187038 /* CreateAnnotationTest.pdf in Resources */ = {isa = PBXBuildFile; fileRef = C97699742A569AA400187038 /* CreateAnnotationTest.pdf */; };
 		C97699792A569C9400187038 /* CAnnotationImportExportViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C97699782A569C9400187038 /* CAnnotationImportExportViewController.m */; };
 		C976997D2A56AD3B00187038 /* CInteractiveFormsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C976997C2A56AD3B00187038 /* CInteractiveFormsViewController.m */; };
+		C97699812A579FEC00187038 /* CPDFPageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C97699802A579FEC00187038 /* CPDFPageViewController.m */; };
 		C9E361142A5273BC004D31BE /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C9E361132A5273BC004D31BE /* AppDelegate.m */; };
 		C9E361172A5273BC004D31BE /* SceneDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C9E361162A5273BC004D31BE /* SceneDelegate.m */; };
 		C9E3611A2A5273BC004D31BE /* CSamplesFuctionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C9E361192A5273BC004D31BE /* CSamplesFuctionViewController.m */; };
@@ -76,6 +77,8 @@
 		C97699782A569C9400187038 /* CAnnotationImportExportViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CAnnotationImportExportViewController.m; sourceTree = "<group>"; };
 		C976997B2A56AD3B00187038 /* CInteractiveFormsViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CInteractiveFormsViewController.h; sourceTree = "<group>"; };
 		C976997C2A56AD3B00187038 /* CInteractiveFormsViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CInteractiveFormsViewController.m; sourceTree = "<group>"; };
+		C976997F2A579FEC00187038 /* CPDFPageViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CPDFPageViewController.h; sourceTree = "<group>"; };
+		C97699802A579FEC00187038 /* CPDFPageViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CPDFPageViewController.m; sourceTree = "<group>"; };
 		C995A2E42A53FEAD00762127 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 		C9E3610F2A5273BC004D31BE /* Samples.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Samples.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		C9E361122A5273BC004D31BE /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
@@ -196,6 +199,15 @@
 			path = InteractiveForms;
 			sourceTree = "<group>";
 		};
+		C976997E2A579F5F00187038 /* PDFPage */ = {
+			isa = PBXGroup;
+			children = (
+				C976997F2A579FEC00187038 /* CPDFPageViewController.h */,
+				C97699802A579FEC00187038 /* CPDFPageViewController.m */,
+			);
+			path = PDFPage;
+			sourceTree = "<group>";
+		};
 		C9E361062A5273BC004D31BE = {
 			isa = PBXGroup;
 			children = (
@@ -233,6 +245,7 @@
 				C976996E2A55959F00187038 /* Annotation */,
 				C97699762A569C4700187038 /* AnnotationImportExport */,
 				C976997A2A56AC0300187038 /* InteractiveForms */,
+				C976997E2A579F5F00187038 /* PDFPage */,
 				C9E3611B2A5273BC004D31BE /* Main.storyboard */,
 				C9E3611E2A5273BF004D31BE /* Assets.xcassets */,
 				C995A2E42A53FEAD00762127 /* Info.plist */,
@@ -341,6 +354,7 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				C97699812A579FEC00187038 /* CPDFPageViewController.m in Sources */,
 				C97699462A540D4200187038 /* CBookmarkViewController.m in Sources */,
 				C9E3611A2A5273BC004D31BE /* CSamplesFuctionViewController.m in Sources */,
 				C97699612A5534D500187038 /* XMLReader.m in Sources */,

+ 0 - 3
Samples/Samples/Bookmark/CBookmarkViewController.m

@@ -67,9 +67,6 @@
         [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
     NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"CreateBookmarkTest"];
     
-    if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
-        [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
-    
     // Save the document in the PDF file
     self.bookmarkURL = [NSURL fileURLWithPath:writeFilePath];
     [document writeToURL:self.bookmarkURL];

+ 7 - 0
Samples/Samples/CSamplesFuctionViewController.m

@@ -19,6 +19,7 @@
 #import "CAnnotaitonViewController.h"
 #import "CAnnotationImportExportViewController.h"
 #import "CInteractiveFormsViewController.h"
+#import "CPDFPageViewController.h"
 
 #import <ComPDFKit/ComPDFKit.h>
 
@@ -168,6 +169,12 @@
             [self.navigationController pushViewController:interactiveFormsVC animated:YES];
         }
             break;
+        case CSamplesTypePDFPage:
+        {
+            CPDFPageViewController *PDFPageVC = [[CPDFPageViewController alloc] initWithDocument:self.document];
+            [self.navigationController pushViewController:PDFPageVC animated:YES];
+        }
+            break;
             
         default:
             break;

+ 21 - 0
Samples/Samples/PDFPage/CPDFPageViewController.h

@@ -0,0 +1,21 @@
+//
+//  CPDFPageViewController.h
+//  Samples
+//
+//  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 "CSamplesBaseViewController.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface CPDFPageViewController : CSamplesBaseViewController
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 448 - 0
Samples/Samples/PDFPage/CPDFPageViewController.m

@@ -0,0 +1,448 @@
+//
+//  CPDFPageViewController.m
+//  Samples
+//
+//  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 "CPDFPageViewController.h"
+
+#import <ComPDFKit/ComPDFKit.h>
+
+//-----------------------------------------------------------------------------------------
+// The sample code illustrates how to operate multiple pages of pdf document, including
+// insert blank page, insert PDF document page, split page, merge page, delete page,
+// rotate page, replace document page and export document page.
+//-----------------------------------------------------------------------------------------
+
+
+
+@interface CPDFPageViewController ()
+
+@property (nonatomic, strong) CPDFDocument *document;
+
+@property (nonatomic, assign) BOOL isRun;
+
+@property (nonatomic, strong) NSString *commandLineStr;
+
+@property (nonatomic, strong) NSURL *insertBlankPageURL;
+
+@property (nonatomic, strong) NSURL *insertPDFPageURL;
+
+@property (nonatomic, strong) NSURL *mergePageURL;
+
+@property (nonatomic, strong) NSURL *removePageURL;
+
+@property (nonatomic, strong) NSURL *rotatePageURL;
+
+@property (nonatomic, strong) NSURL *replacePageURL;
+
+@property (nonatomic, strong) NSURL *extractPageURL;
+
+@property (nonatomic, strong) NSMutableArray *splitFilePaths;
+
+@end
+
+@implementation CPDFPageViewController
+
+#pragma mark - UIViewController Methods
+
+- (void)viewDidLoad {
+    [super viewDidLoad];
+    // Do any additional setup after loading the view.
+    self.explainLabel.text = NSLocalizedString(@"The sample code illustrates how to operate multiple pages of pdf document, including insert blank page, insert PDF document page, split page, merge page, delete page, rotate page, replace document page and export document page.", nil);
+    
+    self.commandLineTextView.text = @"";
+    self.isRun = NO;
+    self.commandLineStr = @"";
+    
+    self.splitFilePaths = [NSMutableArray array];
+}
+
+#pragma mark - Samples Methods
+
+// insert blank page
+- (void)insertBlankPage:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 1: Insert a blank A4-sized page into the sample document\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Opening the Samples PDF File\n"];
+    
+    // Save a document in Sandbox
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"PDFPage"];
+    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"Samples",@"CommonFivePage"];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"InsertBlankPage"];
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
+        [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
+    
+    // Save the document in the PDF file
+    self.insertBlankPageURL = [NSURL fileURLWithPath:writeFilePath];
+    
+    document = [[CPDFDocument alloc] initWithURL:self.insertBlankPageURL];
+    // insert blank page
+    [document insertPage:CGSizeMake(595, 852) atIndex:1];
+    
+    [document writeToURL:self.insertBlankPageURL];
+     
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Insert PageIndex : 1\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Size : 595*842\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in InsertBlankPage.pdf\n"];
+}
+
+// insert PDF document
+- (void)insertPDFPPage:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 2: Import pages from another document into the example document\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Opening the Samples PDF File\n"];
+    
+    // get PDF document
+    NSString *filePathTest = [[NSBundle mainBundle] pathForResource:@"text" ofType:@"pdf"];
+    CPDFDocument *insertDocument = [[CPDFDocument alloc] initWithURL:[NSURL fileURLWithPath:filePathTest]];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Open the document to be imported\n"];
+    
+    NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
+    [indexSet addIndex:0];
+    
+    // Save a document in Sandbox
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"PDFPage"];
+    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"Samples",@"CommonFivePage"];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"InsertPDFPage"];
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
+        [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
+    
+    // Save the document in the PDF file
+    self.insertPDFPageURL = [NSURL fileURLWithPath:writeFilePath];
+    
+    document = [[CPDFDocument alloc] initWithURL:self.insertPDFPageURL];
+    
+    // insert PDF document
+    [document importPages:indexSet fromDocument:insertDocument atIndex:1];
+    [document writeToURL:self.insertPDFPageURL];
+    
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in InsertPDFPage.pdf\n"];
+}
+
+// split page
+- (void)splitPages:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 3: Split a PDF document into multiple pages\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Opening the Samples PDF File\n"];
+    
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"PDFPage"];
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    
+    for (int i = 0; i < document.pageCount; i++) {
+        CPDFDocument *splitDocument = [[CPDFDocument alloc] init];
+        NSIndexSet *index = [[NSIndexSet alloc] initWithIndex:i];
+        
+        NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@%d.pdf",writeDirectoryPath,@"CommonFivePageSplitPage",i];
+        
+        [self.splitFilePaths addObject:writeFilePath];
+        
+        [splitDocument importPages:index fromDocument:document atIndex:0];
+        [splitDocument writeToURL:[NSURL fileURLWithPath:writeFilePath]];
+        
+        self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Done. Results saved in CommonFivePageSplitPage%d.pdf\n", i];
+    }
+}
+
+// merge page
+- (void)mergePages:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 4: Merge split documents\n"];
+    
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"PDFPage"];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"MergePages"];
+    
+    CPDFDocument *mergeDocument = [[CPDFDocument alloc] init];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    
+    for (int i = 0; i < self.splitFilePaths.count; i++) {
+        CPDFDocument *document = [[CPDFDocument alloc] initWithURL:[NSURL fileURLWithPath:self.splitFilePaths[i]]];
+        self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"Opening CommonFivePageSplitPage%d.pdf\n", i];
+        NSIndexSet *index = [[NSIndexSet alloc] initWithIndex:0];
+        [mergeDocument importPages:index fromDocument:document atIndex:i];
+    }
+    
+    self.mergePageURL = [NSURL fileURLWithPath:writeFilePath];
+    [mergeDocument writeToURL:self.mergePageURL];
+    
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in MergePages.pdf\n"];
+}
+
+// delete page
+- (void)deletePages:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 5: Delete the specified page of the document\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Opening the Samples PDF File\n"];
+    
+    // Save a document in Sandbox
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"PDFPage"];
+    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"Samples",@"CommonFivePage"];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"RemovePages"];
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
+        [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
+    
+    self.removePageURL = [NSURL fileURLWithPath:writeFilePath];
+    document = [[CPDFDocument alloc] initWithURL:self.removePageURL];
+    
+    NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
+    for (int i = 1; i < document.pageCount; i = i+2) {
+        [indexSet addIndex:i];
+    }
+    
+    [document removePageAtIndexSet:indexSet];
+    [document writeToURL:self.removePageURL];
+    
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in RemovePages.pdf\n"];
+}
+
+// rotate page
+- (void)rotatePages:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 6: Rotate document pages\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Opening the Samples PDF File\n"];
+    
+    // Save a document in Sandbox
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"PDFPage"];
+    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"Samples",@"CommonFivePage"];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"RotatePage"];
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
+        [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
+    
+    self.rotatePageURL = [NSURL fileURLWithPath:writeFilePath];
+    document = [[CPDFDocument alloc] initWithURL:self.rotatePageURL];
+    
+    CPDFPage *page = [document pageAtIndex:0];
+    page.rotation += 90;
+    
+    [document writeToURL:self.rotatePageURL];
+    
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in RotatePage.pdf\n"];
+}
+
+// replace document page
+- (void)repalcePages:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 7: Replace specified pages of example documentation with other documentation specified pages\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Opening the Samples PDF File\n"];
+    
+    // Save a document in Sandbox
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"PDFPage"];
+    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"Samples",@"CommonFivePage"];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"ReplacePages"];
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
+        [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
+    
+    self.replacePageURL = [NSURL fileURLWithPath:writeFilePath];
+    document = [[CPDFDocument alloc] initWithURL:self.replacePageURL];
+    
+    // get PDF document
+    NSString *filePathTest = [[NSBundle mainBundle] pathForResource:@"text" ofType:@"pdf"];
+    CPDFDocument *insertDocument = [[CPDFDocument alloc] initWithURL:[NSURL fileURLWithPath:filePathTest]];
+    
+    NSIndexSet *inserSet = [[NSIndexSet alloc]  initWithIndex:0];
+    NSIndexSet *removeSet = [[NSIndexSet alloc]  initWithIndex:1];
+    [document removePageAtIndexSet:removeSet];
+    [document importPages:inserSet fromDocument:insertDocument atIndex:1];
+    
+    [document writeToURL:self.replacePageURL];
+    
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in ReplacePages.pdf\n"];
+}
+
+// export document page
+- (void)extractPages:(CPDFDocument *)document {
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 8: Extract specific pages of a document\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Opening the Samples PDF File\n"];
+    
+    // Save a document in Sandbox
+    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
+    NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"PDFPage"];
+    NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@/%@.pdf", @"Documents",@"Samples",@"CommonFivePage"];
+    
+    // Copy file
+    if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
+        [[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
+    NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"ExtractPages"];
+    
+    NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
+    [indexSet addIndex:0];
+    [indexSet addIndex:1];
+    
+    self.extractPageURL = [NSURL fileURLWithPath:writeFilePath];
+    
+    CPDFDocument *extractDocument = [[CPDFDocument alloc] init];
+    [extractDocument importPages:indexSet fromDocument:document atIndex:0];
+    
+    [extractDocument writeToURL:self.extractPageURL];
+    
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in ExtractPages.pdf\n"];
+}
+
+- (void)openFileWithURL:(NSURL *)url {
+    UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:@[url] applicationActivities:nil];
+        activityVC.definesPresentationContext = YES;
+    if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
+        activityVC.popoverPresentationController.sourceView = self.openfileButton;
+        activityVC.popoverPresentationController.sourceRect = self.openfileButton.bounds;
+    }
+    [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!");
+        }
+    };
+}
+
+#pragma mark - Action
+
+- (IBAction)buttonItemClick_openFile:(id)sender {
+    // Determine whether to export the document
+    if (self.isRun) {
+        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Choose a file to open...", nil) message:@"" preferredStyle:UIAlertControllerStyleAlert];
+        if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
+            alertController.popoverPresentationController.sourceView = self.openfileButton;
+            alertController.popoverPresentationController.sourceRect = self.openfileButton.bounds;
+        }
+        
+        UIAlertAction *insertBlankAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   InsertBlankPage.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.insertBlankPageURL];
+        }];
+        [alertController addAction:insertBlankAction];
+        
+        UIAlertAction *insertPDFAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   InsertPDFPage.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.insertPDFPageURL];
+        }];
+        [alertController addAction:insertPDFAction];
+        
+        for (int i = 0; i < self.document.pageCount; i++) {
+            NSString *imageName = [NSString stringWithFormat:@"CommonFivePageSplitPage%d.pdf", i];
+            UIAlertAction *imageAction = [UIAlertAction actionWithTitle:NSLocalizedString(imageName, nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+                // Open CreateBookmarkTest.pdf
+                [self openFileWithURL:[NSURL fileURLWithPath:self.splitFilePaths[i]]];
+            }];
+            [alertController addAction:imageAction];
+        }
+        
+        UIAlertAction *mergeAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   MergePage.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.mergePageURL];
+        }];
+        [alertController addAction:mergeAction];
+        
+        UIAlertAction *removePagesAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   RemovePages.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.removePageURL];
+        }];
+        [alertController addAction:removePagesAction];
+        
+        UIAlertAction *rotatePagesAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   RotatePage.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.rotatePageURL];
+        }];
+        [alertController addAction:rotatePagesAction];
+        
+        UIAlertAction *replacePagesAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   ReplacePages.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.replacePageURL];
+        }];
+        [alertController addAction:replacePagesAction];
+        
+        UIAlertAction *ExtractPagesAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"   ExtractPages.pdf   ", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            // Open CreateBookmarkTest.pdf
+            [self openFileWithURL:self.extractPageURL];
+        }];
+        [alertController addAction:ExtractPagesAction];
+        
+        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];
+        
+        
+        [alertController addAction:cancelAction];
+        
+        [self presentViewController:alertController animated:NO completion:nil];
+    } else {
+        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Choose a file to open...", nil) message:@"" preferredStyle:UIAlertControllerStyleAlert];
+        if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
+            alertController.popoverPresentationController.sourceView = self.openfileButton;
+            alertController.popoverPresentationController.sourceRect = self.openfileButton.bounds;
+        }
+        
+        UIAlertAction *noAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"No files for this sample.", nil) style:UIAlertActionStyleDefault handler:nil];
+        
+        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];
+        
+        [alertController addAction:noAction];
+        [alertController addAction:cancelAction];
+        
+        [self presentViewController:alertController animated:NO completion:nil];
+    }
+}
+
+- (IBAction)buttonItemClick_run:(id)sender {
+    self.isRun = YES;
+    
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Running PDFPage sample...\n\n"];
+    [self insertBlankPage:self.document];
+    [self insertPDFPPage:self.document];
+    [self splitPages:self.document];
+    [self mergePages:self.document];
+    [self deletePages:self.document];
+    [self rotatePages:self.document];
+    [self repalcePages:self.document];
+    [self extractPages:self.document];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"\nDone!\n"];
+    self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
+    
+    // Refresh commandline message
+    self.commandLineTextView.text = self.commandLineStr;
+}
+
+@end