ios - Drawing PDF from two views -



ios - Drawing PDF from two views -

i have first view firstview , draw sec view secondview , add together subview firstview. have method creates firstview pdf file:

-(void)createpdffromuiview:(uiview*)firstview { nsmutabledata *pdfdata = [nsmutabledata data]; uigraphicsbeginpdfcontexttodata(pdfdata, self.view.bounds, nil); uigraphicsbeginpdfpage(); cgcontextref pdfcontext = uigraphicsgetcurrentcontext(); [firstview.layer drawincontext:pdfcontext]; uigraphicsendpdfcontext(); nsarray* documentdirectories = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask,yes); nsstring* documentdirectory = [documentdirectories objectatindex:0]; nsstring* documentdirectoryfilename = [documentdirectory stringbyappendingpathcomponent:@"resolution.pdf"]; [pdfdata writetofile:documentdirectoryfilename atomically:yes]; nslog(@"documentdirectoryfilename: %@",documentdirectoryfilename); }

how can draw 1 pdf 2 views, pdf file must include @ 1 page firstview , secondview

added

in viewcontroller in loadview method

awfirstview *firstview = [[awfirstview alloc] init]; self.view = firstview; self.secondview = [[awsecondtview alloc] initwithframe:cgrectmake(0, 50, 300., 300.)]; [self.secondview setbackgroundcolor:[uicolor clearcolor]]; self.createpdfbutton = [uibutton buttonwithtype:uibuttontypecustom]; self.createpdfbutton.frame =cgrectmake(0, 0, 88., 50.); [self.createpdfbutton setbackgroundcolor:[uicolor whitecolor]]; [self.createpdfbutton addtarget:self action:@selector(createpdf) forcontrolevents:uicontroleventtouchupinside]; [self updateview]; [self.view addsubview:self.drawwindow]; [self.view addsubview:self.createpdfbutton];

in updateview this:

-(void)updateview { if(![self isviewloaded]) return; [[awservices services].uicontext updateobjectincurrentcontext:&_resolution]; awfirstview *view = (awfirstview *)self.view; view.post = _resolution.contact.officialpersonpost; view.name = _resolution.contact.officialpersonfullname; [view.superview setneedsdisplay];

in

-(void)createpdf{ [self createpdffromuiview:self.view];

}

try this:

uigraphicsbeginpdfcontexttodata(pdfdata, firstview.bounds, nil); uigraphicsbeginpdfpage(); cgcontextref pdfcontext = uigraphicsgetcurrentcontext(); [firstview.layer drawincontext:pdfcontext];

notice sending drawincontext: firstview, opposed myview doing. if firstview passed in method, should give expected result.

edit: not adding secondview subview; (third line):

self.secondview = [[awsecondtview alloc] initwithframe:cgrectmake(0, 50, 300., 300.)]; [self.secondview setbackgroundcolor:[uicolor clearcolor]]; [self.firstview addsubview:self.secondview];

furthermore, assignment doing self.view not good:

self.view = firstview;

either do:

[self.view addsubview:self.firstview];

or define loadview in view controller , assign there self.view.

ios objective-c pdf uiview

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -