现在我正在使用这段代码。Pdf 正在生成,但图像未显示。
-(void)imagePickerController:(UIImagePickerController *)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSLog(@"%@",info);
//selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];
NSLog(@" selected image is - %@",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 is %@",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 is %@",imageStr);
UIImage *image=[UIImage imageNamed:imageStr];
[image drawInRect:imagerect];
}