how to convert a selected image from iphone library to pdf in ios sdk -
now using code. pdf generating image not displaying.
-(void)imagepickercontroller:(uiimagepickercontroller *)pickerdidfinishpickingmediawithinfo:(nsdictionary *)info { nslog(@"%@",info); //selectedimage = [info objectforkey:uiimagepickercontrolleroriginalimage]; uiimage *image=[info objectforkey:uiimagepickercontrolleroriginalimage]; nslog(@" selected image - %@",image); imagestr=[nsstring stringwithformat:@"%@",image]; nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring *localfilepath=[documentsdirectory stringbyappendingpathcomponent:@"images.pdf"]; nslog(@"file path %@",localfilepath); [self pdfgenerate:localfilepath]; uigraphicsendpdfcontext(); [imagepicker dismissviewcontrolleranimated:yes completion:nil]; } -(void)pdfgenerate:(nsstring *)filepath { uigraphicsbeginpdfcontexttofile(filepath, cgrectzero, nil); uigraphicsbeginpdfpagewithinfo(cgrectmake(0, 0, 300, 300), nil); [self convertimagetopdf]; } -(void)convertimagetopdf { cgrect imagerect=cgrectmake(0, 0, 300, 300); nslog(@"image %@",imagestr); uiimage *image=[uiimage imagenamed:imagestr]; [image drawinrect:imagerect]; }
you saving selected image in nsstring object imagestr
(imagestr=[nsstring stringwithformat:@"%@",image];)
so when creating image inside convertimagetopdf
method (uiimage *image=[uiimage imagenamed:imagestr];), image object nil
. pdf blank.
instead can have uiimage reference image picked picker. use reference inside convertimagetopdf
draw.
update code:
inside didfinishpickingmediawithinfo
pickedimage=[info objectforkey:uiimagepickercontrolleroriginalimage];
inside convertimagetopdf
cgrect imagerect=cgrectmake(0, 0, 300, 300); [pickedimage drawinrect:imagerect];
pickedimage
object of type uiimage.
Comments
Post a Comment