//--------------------------------------------------------------------------------------- // Copyright (c) 2001-2012 by PDFTron Systems Inc. All Rights Reserved. // Consult legal.txt regarding legal and license information. //--------------------------------------------------------------------------------------- #import #import int main(int argc, char *argv[]) { int ret = 0; [PDFNet Initialize: 0]; // Sample 1 - Split a PDF document into multiple pages @try { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSLog(@"_______________________________________________"); NSLog(@"Sample 1 - Split a PDF document into multiple pages..."); NSLog(@"Opening the input pdf..."); PDFDoc *in_doc = [[[PDFDoc alloc] initWithFilepath: @"../../TestFiles/newsletter.pdf"] autorelease]; [in_doc InitSecurityHandler]; int page_num = [in_doc GetPageCount]; int i; for (i=1; i<=page_num; ++i) { PDFDoc *new_doc = [[[PDFDoc alloc] init] autorelease]; NSString *output_file = [@"../../TestFiles/Output/" stringByAppendingFormat: @"newsletter_split_page_%d.pdf", i]; [new_doc InsertPages: 0 sourceDoc: in_doc startPage: i endPage: i flag: e_pd_none]; [new_doc SaveToFile: output_file flags: e_remove_unused]; NSLog(@"Done. Result saved in newsletter_split_page_%d.pdf", i); } [pool release]; } @catch(NSException *e) { NSLog(@"%@", [e reason]); ret = 1; } // Sample 2 - Merge several PDF documents into one @try { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSLog(@"_______________________________________________"); NSLog(@"Sample 2 - Merge several PDF documents into one..."); PDFDoc *new_doc = [[[PDFDoc alloc] init] autorelease]; [new_doc InitSecurityHandler]; int page_num = 15; int i; for (i=1; i<=page_num; ++i) { NSString *input_file = [@"../../TestFiles/Output/" stringByAppendingFormat: @"newsletter_split_page_%d.pdf", i]; NSLog(@"Opening newsletter_split_page_%d.pdf", i); PDFDoc *in_doc = [[[PDFDoc alloc] initWithFilepath: input_file] autorelease]; [new_doc InsertPages: i sourceDoc: in_doc startPage: 1 endPage: [in_doc GetPageCount] flag: e_pd_none]; } [new_doc SaveToFile: @"../../TestFiles/Output/newsletter_merge_pages.pdf" flags: e_remove_unused]; NSLog(@"Done. Result saved in newsletter_merge_pages.pdf"); [pool release]; } @catch(NSException *e) { NSLog(@"%@", [e reason]); ret = 1; } // Sample 3 - Delete every second page @try { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSLog(@"_______________________________________________"); NSLog(@"Sample 3 - Delete every second page..."); NSLog(@"Opening the input pdf..."); PDFDoc *in_doc = [[[PDFDoc alloc] initWithFilepath: @"../../TestFiles/newsletter.pdf"] autorelease]; [in_doc InitSecurityHandler]; int page_num = [in_doc GetPageCount]; while (page_num>=1) { PageIterator *itr = [in_doc GetPageIterator: page_num]; [in_doc PageRemove: itr]; page_num -= 2; } [in_doc SaveToFile: @"../../TestFiles/Output/newsletter_page_remove.pdf" flags: 0]; NSLog(@"Done. Result saved in newsletter_page_remove.pdf..."); [pool release]; } @catch(NSException *e) { NSLog(@"%@", [e reason]); ret = 1; } // Sample 4 - Inserts a page from one document at different // locations within another document @try { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSLog(@"_______________________________________________"); NSLog(@"Sample 4 - Insert a page at different locations..."); NSLog(@"Opening the input pdf..."); PDFDoc *in1_doc = [[[PDFDoc alloc] initWithFilepath: @"../../TestFiles/newsletter.pdf"] autorelease]; [in1_doc InitSecurityHandler]; PDFDoc *in2_doc = [[[PDFDoc alloc] initWithFilepath: @"../../TestFiles/fish.pdf"] autorelease]; [in2_doc InitSecurityHandler]; PageIterator *src_page = [in2_doc GetPageIterator: 1]; int page_num = [in1_doc GetPageCount]; int i; for (i=1; i