objective c - how can i edit existing pdf file in ios like copy ,zoom,background color,font -
i have load pdf file in uiwebview
want copy content pdf file.
hear code :
- (void)viewdidload { [super viewdidload]; [self editpdf]; } - (void)editpdf { nsstring* filename = @"new.pdf"; nsarray *arraypaths = nssearchpathfordirectoriesindomains( nsdocumentdirectory, nsuserdomainmask, yes); nsstring *path = [arraypaths objectatindex:0]; nsstring* pdffilename = [path stringbyappendingpathcomponent:filename]; nsstring *templatepath = [[nsbundle mainbundle] pathforresource:@"objective_c_tutorial" oftype:@"pdf"]; //create empty pdf file; uigraphicsbeginpdfcontexttofile(pdffilename, cgrectmake(0,0,600,768), nil); cfurlref url = cfurlcreatewithfilesystempath (null, (cfstringref)templatepath, kcfurlposixpathstyle, 0); //open template file cgpdfdocumentref templatedocument = cgpdfdocumentcreatewithurl(url); cfrelease(url); //get amount of pages in template size_t count = cgpdfdocumentgetnumberofpages(templatedocument); //for each page in template (size_t pagenumber = 1; pagenumber <= count; pagenumber++) { //get bounds of template page cgpdfpageref templatepage = cgpdfdocumentgetpage(templatedocument, pagenumber); cgrect templatepagebounds = cgpdfpagegetboxrect(templatepage, kcgpdfcropbox); //create empty page corresponding bounds in new document uigraphicsbeginpdfpagewithinfo(templatepagebounds, nil); cgcontextref context = uigraphicsgetcurrentcontext(); //flip context due different origins cgcontexttranslatectm(context, 0.0, templatepagebounds.size.height); cgcontextscalectm(context, 1.0, -1.0); //copy content of template page on corresponding page in new file cgcontextdrawpdfpage(context, templatepage); //flip context cgcontexttranslatectm(context, 0.0, templatepagebounds.size.height); cgcontextscalectm(context, 1.0, -1.0); //create dictionary font uifont *font = [uifont fontwithname: @"courier" size:12]; nsdictionary *attribdict = [[nsdictionary alloc] initwithobjectsandkeys: font, nsfontattributename, nil]; /* here can drawings */ [@"test" drawatpoint:cgpointmake(200, 300) withattributes:attribdict]; } cgpdfdocumentrelease(templatedocument); uigraphicsendpdfcontext(); [self showpdffile]; } -(void)showpdffile { nsstring* filename = @"new.pdf"; nsarray *arraypaths = nssearchpathfordirectoriesindomains( nsdocumentdirectory, nsuserdomainmask, yes); nsstring *path = [arraypaths objectatindex:0]; nsstring* pdffilename = [path stringbyappendingpathcomponent:filename]; uiwebview* webview = [[uiwebview alloc] initwithframe:cgrectmake(0,0,360,768)]; nsurl *url = [nsurl fileurlwithpath:pdffilename]; nsurlrequest *request = [nsurlrequest requestwithurl:url]; [webview setscalespagetofit:yes]; [webview loadrequest:request]; [self.view addsubview:webview]; }
Comments
Post a Comment