我有一个图像数组,我正在尝试使用该images创建pdf。我可以创建多个页面的pdf文件。 我检查了一个教程,但它不适合我。 How to create a multiple page PDF in ios6? 请帮帮我
答案 0 :(得分:1)
这对我有用:
NSArray *pageArray = yourImageArray;
NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, CGRectMake(0, 0, 595, 842), nil);
for (UIImage *theImage in pageArray) {
UIGraphicsBeginPDFPage();
NSData *jpegData = UIImageJPEGRepresentation(theImage, 0.5);
CGDataProviderRef dp = CGDataProviderCreateWithCFData((__bridge CFDataRef)jpegData);
CGImageRef cgImage = CGImageCreateWithJPEGDataProvider(dp, NULL, true, kCGRenderingIntentDefault);
[[UIImage imageWithCGImage:cgImage] drawInRect:CGRectMake(0, 0, theImage.size.width, theImage.size.height)];
}
UIGraphicsEndPDFContext();
return pdfData;