Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在iPhone中以编程方式创建多页pdf_Ios_Iphone_Objective C_Pdf_Nsmutablearray - Fatal编程技术网

Ios 如何在iPhone中以编程方式创建多页pdf

Ios 如何在iPhone中以编程方式创建多页pdf,ios,iphone,objective-c,pdf,nsmutablearray,Ios,Iphone,Objective C,Pdf,Nsmutablearray,我有一个图像数组,我正在尝试用这些图像创建pdf。如何创建多页pdf文件。 我检查了一个教程,但它对我不起作用。 请帮助我这对我有用: NSArray *pageArray = yourImageArray; NSMutableData *pdfData = [NSMutableData data]; UIGraphicsBeginPDFContextToData(pdfData, CGRectMake(0, 0, 595, 842), nil); for (UIImage *theImag

我有一个图像数组,我正在尝试用这些图像创建pdf。如何创建多页pdf文件。 我检查了一个教程,但它对我不起作用。 请帮助我

这对我有用:

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;

要开始pdf中的每个新页面,请使用

UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageWidth, pageHeight), nil);
这可能会有帮助-