【发布时间】:2015-02-05 13:54:30
【问题描述】:
我需要在 iOS 中创建一个包含多个图像的单页 pdf 文件。我使用了这个代码:
- (void)createPDFWithImagesArray:(NSMutableArray *)array andFileName:(NSString *)fileName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *PDFPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.pdf",fileName]];
for (UIImage *image in array)
{
// Mark the beginning of a new page.
CGRect pagebounds=CGRectMake(0, 0, image.size.width, image.size.height);
CGRect imagebounds=CGRectMake(0, 0, image.size.width, image.size.height);
UIGraphicsBeginPDFContextToFile(PDFPath, pagebounds, nil);
{
UIGraphicsBeginPDFPage();
[image drawInRect:imagebounds];
}
}
UIGraphicsEndPDFContext();
}
但它没有生成 pdf 文件并且出现错误,请任何人帮助我...
【问题讨论】:
-
[1094:190271] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSArrayM 大小]:无法识别的选择器发送到实例 0x15e84a70”
-
收到此错误后,我已分配 array=[[NSMutablearray alloc]init];在 for 循环中,但它正在生成空的 pdf 文件..
-
您确定将数组传递给函数吗?如果你传递一个未初始化的变量,你一定会得到那个错误(无效的 Argunebt .....并且不要在函数内初始化数组,否则你会清除图像。
-
@paulo 我是 IOS 新手,请您发送一些代码..
-
-(void)imagePickerContoller:(SFMultiImagePickerController *)imagePicker didFinishPickingMediaWithInfo:(NSArray *)info { [self dismissViewControllerAnimated:YES completion:nil]; [图片选择添加对象:信息]; NSLog(@" 选择的图像是 %@",imagesselected); [self createPDFWithImagesArray:imagesselected and FileName:@"mypdf"]; } 通过这个函数我调用了这个方法..
标签: ios objective-c