【问题标题】:how to create multiple pages pdf programmatically in iPhone如何在 iPhone 中以编程方式创建多页 pdf
【发布时间】:2014-03-10 11:52:42
【问题描述】:
【问题讨论】:
标签:
ios
iphone
objective-c
pdf
nsmutablearray
【解决方案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;
【解决方案2】:
要开始 pdf 中的每个新页面,请使用
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageWidth, pageHeight), nil);