//--------------------------------------------------------------------------------------- // Copyright (c) 2001-2012 by PDFTron Systems Inc. All Rights Reserved. // Consult legal.txt regarding legal and license information. //--------------------------------------------------------------------------------------- #import #import //--------------------------------------------------------------------------------------- // The sample code shows how to edit the page display list and how to modify graphics state // attributes on existing Elements. In particular the sample program strips all images from // the page and changes text color to blue. //--------------------------------------------------------------------------------------- static void ProcessElements(ElementReader *reader, ElementWriter *writer) { Element *element; while (element = [reader Next]) // Read page contents { switch ([element GetType]) { case e_image: case e_inline_image: // remove all images by skipping them break; case e_text_obj:// Process text strings... { // Set all text to blue color. GState *gs = [element GetGState]; [gs SetFillColorSpace: [ColorSpace CreateDeviceRGB]]; ColorPt *cp = [[ColorPt alloc] initWithX: 0 y: 0 z: 1 w: 0]; [gs SetFillColorWithColorPt: cp]; [writer WriteElement: element]; break; } case e_form:// Recursively process form XObjects { [reader FormBegin]; ProcessElements(reader, writer); [reader End]; break; } default: [writer WriteElement: element]; } } } int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; int ret = 0; [PDFNet Initialize: 0]; @try { NSLog(@"-------------------------------------------------"); // Open the test file NSLog(@"Opening the input file..."); PDFDoc *doc = [[PDFDoc alloc] initWithFilepath: @"../../TestFiles/newsletter.pdf"]; [doc InitSecurityHandler]; ElementWriter *writer = [[ElementWriter alloc] init]; ElementReader *reader = [[ElementReader alloc] init]; PageIterator *itr = [doc GetPageIterator: 1]; while ([itr HasNext]) { Page *page = [itr Current]; [reader ReaderBeginWithPage: page ocg_context: 0]; [writer Begin: page placement: e_replacement page_coord_sys: NO]; ProcessElements(reader, writer); [writer End]; [reader End]; [itr Next]; } [doc SaveToFile: @"../../TestFiles/Output/newsletter_edited.pdf" flags: e_remove_unused]; NSLog(@"Done. Result saved in newsletter_edited.pdf..."); } @catch(NSException *e) { NSLog(@"Caught PDFNet exception: %@", [e reason]); ret = 1; } [pool release]; return ret; }