Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.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 CGPDFDocumentRef对某些PDF文件有效,但对其他文件无效_Ios_Objective C - Fatal编程技术网

Ios CGPDFDocumentRef对某些PDF文件有效,但对其他文件无效

Ios CGPDFDocumentRef对某些PDF文件有效,但对其他文件无效,ios,objective-c,Ios,Objective C,我正在尝试使用CGPDFDocumentRef将PDF的单个页面转换为图像。但是,这只适用于某些PDF,而不适用于其他PDF(例如,它适用于但不适用于)。有什么区别 我的PDF转换代码: -(UIImage *)pdfToImg: (NSURL *)pdfURL { // create CGPDF from URL CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL); // get r

我正在尝试使用CGPDFDocumentRef将PDF的单个页面转换为图像。但是,这只适用于某些PDF,而不适用于其他PDF(例如,它适用于但不适用于)。有什么区别

我的PDF转换代码:

-(UIImage *)pdfToImg: (NSURL *)pdfURL {

    // create CGPDF from URL
    CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);

    // get reference to page
    CGPDFPageRef page1 = CGPDFDocumentGetPage(pdf, 1); // page 1

    // get size of page
    CGRect pageRect = CGPDFPageGetBoxRect(page1, kCGPDFMediaBox);
    CGSize pageSize = pageRect.size;

    // edit DPI
    float dpi = 300.0 / 72.0; // change numerator to increase or decrease dpi
    pageSize.width = pageSize.width * dpi;
    pageSize.height = pageSize.height * dpi;

    // ---conversion process---
    UIGraphicsBeginImageContext(pageSize);

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
    CGContextTranslateCTM(context, 0.0, pageSize.height);
    CGContextScaleCTM(context, dpi, -dpi);
    CGContextSaveGState(context);
    //CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(pdfPageRef, kCGPDFCropBox, CGRectMake(0, 0, pageSize.width, pageSize.height), 0, true);
    //CGContextConcatCTM(context, pdfTransform);
    CGContextDrawPDFPage(context, page1);
    CGContextRestoreGState(context);
    // ------

    // create image
    UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return resultingImage;
}
提前谢谢你