iphone - Saving Annotations and Pdf to a new Pdf file in IOS 5 -


i'm working on pdf annotations application , need save annotation when tried save annotations , pdf content new pdf , annotations saved content of pdf not ? here function :

-(void)save_doc_as_pdf:(readermaintoolbar *)toolbar backbutton:(uibutton *)button {     nserror *error;     nsstring *pdfpath = [document.fileurl absolutestring];     nsstring *newpath = [pdfpath stringbyreplacingoccurrencesofstring:@"file://localhost" withstring:@""];      nsstring *newpdfpath = [thenewpath stringbyreplacingoccurrencesofstring:@".pdf" withstring:@"_1.pdf"];     nsdata *pdfdata = [nsdata datawithcontentsoffile:[document.fileurl path] options:nsdatareadinguncached error:&error];     if (pdfdata == nil) {         nslog(@"data nil !!!!");      }      if (error)     {         nslog(@"%@", [error localizeddescription]);         return;     }     else     nslog(@"data has loaded successfully.");     //if fails create new file, returns     if (![[nsfilemanager defaultmanager] createfileatpath:newpdfpath contents:pdfdata attributes:nil])     {         return;     }      nsurl *url = [nsurl fileurlwithpath:newpath];     cgpdfdocumentref pdf_document = cgpdfdocumentcreatewithurl ((__bridge_retained cfurlref) url);     size_t count = cgpdfdocumentgetnumberofpages(pdf_document);      if (count == 0)     {         nslog(@"pdf needs @ least 1 page");         return;     }      cgrect papersize = cgrectmake(0, 0,842, 1190);      uigraphicsbeginpdfcontexttofile(newpdfpath , papersize, nil);     // cgpdfpageref page = cgpdfdocumentgetpage(document, 1);     uigraphicsbeginpdfpagewithinfo(papersize, nil);     cgcontextref currentcontext = uigraphicsgetcurrentcontext();      // flip context page right way (landscape app)     cgcontextscalectm(currentcontext, 1, -1);     // rotate coordinate system (rotation = m_pi or -m_pi landscape)     //cgcontextrotatectm(currentcontext, rotation/ 2);      cgpdfpageref page = cgpdfdocumentgetpage (pdf_document, 1); // grab page 1 of pdf     cgcontextdrawpdfpage (currentcontext, page); // draw page 1 graphics context      //flip context annotations right way     cgcontextscalectm(currentcontext, 1, -1);     //cgcontextrotatectm(currentcontext, rotation / 2);     //render layer of annotations view in context     [startdraw.layer renderincontext:currentcontext];     uigraphicsendpdfcontext();     cgpdfdocumentrelease (pdf_document);  } 

hello find solution saving annotaion on pdf document , want shar here code :

-(void)save_the_pdf:(readermaintoolbar *)toolbar backbutton:(uibutton *)button{     nsmutablearray *urlstableobject=[[nsmutablearray alloc] init];     nsmutablearray *urlstable=[[nsmutablearray alloc] init];     nsuserdefaults *datastoreurls;     nsstring *originalpdfname = [document.filename stringbyreplacingoccurrencesofstring:@".pdf" withstring:@""];       nsstring *originalpdfpath = [document.filename stringbyreplacingoccurrencesofstring:@".pdf" withstring:@""];     nsstring* thenewpath = [[nsbundle mainbundle] pathforresource:originalpdfpath oftype:@"pdf"];     nsstring *newpdfpath = [thenewpath stringbyreplacingoccurrencesofstring:@".pdf" withstring:@"_1.pdf"];      cgpdfdocumentref pdf = cgpdfdocumentcreatewithurl((__bridge cfurlref)[[nsbundle mainbundle] urlforresource:originalpdfname withextension:@"pdf"]);      const size_t numberofpages = cgpdfdocumentgetnumberofpages(pdf);      nsmutabledata* data = [nsmutabledata data];     uigraphicsbeginpdfcontexttodata(data, cgrectzero, nil);      for(size_t page = 1; page <= numberofpages; page++)     {           //  current page , page frame         cgpdfpageref pdfpage = cgpdfdocumentgetpage(pdf, page);         const cgrect pageframe = cgpdfpagegetboxrect(pdfpage, kcgpdfmediabox);          uigraphicsbeginpdfpagewithinfo(pageframe, nil);          //  draw page (flipped)         cgcontextref ctx = uigraphicsgetcurrentcontext();         cgcontextsavegstate(ctx);         cgcontextscalectm(ctx, 1, -1);         cgcontexttranslatectm(ctx, 0, -pageframe.size.height);         cgcontextdrawpdfpage(ctx, pdfpage);         cgcontextrestoregstate(ctx);         if (page == currentpage) {         [startdraw.layer renderincontext:ctx];         }     }      uigraphicsendpdfcontext();      cgpdfdocumentrelease(pdf);     //pdf = nil;     if (![[nsfilemanager defaultmanager] createfileatpath:newpdfpath contents:data attributes:nil])     {         return;     }      //  'data'...      datastoreurls=[nsuserdefaults standarduserdefaults];      if([datastoreurls objectforkey:@"allurls"]!=null){         urlstableobject=[datastoreurls objectforkey:@"allurls"];         int index=[urlstableobject count];         urlstable=[[nsmutablearray alloc] initwitharray:urlstableobject];         [urlstable insertobject:newpdfpath atindex:index];         [datastoreurls setobject:urlstable forkey:@"allurls"];     }else{         [urlstable addobject:newpdfpath];         [datastoreurls setobject:urlstable forkey:@"allurls"];     }     [datastoreurls synchronize]; } 

Comments