Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.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 以正确的方向呈现PDF的正确方法是什么?_Ios_Objective C_Pdf_Pdf Generation_Core Graphics - Fatal编程技术网

Ios 以正确的方向呈现PDF的正确方法是什么?

Ios 以正确的方向呈现PDF的正确方法是什么?,ios,objective-c,pdf,pdf-generation,core-graphics,Ios,Objective C,Pdf,Pdf Generation,Core Graphics,我使用核心图形,CGContextDrawPDFPage函数渲染PDF。我试图在图像视图中显示PDF页面。这些页面呈现得非常完美。但有些页面的方向不正确。有些是颠倒过来的。这种情况只发生在少数PDF/页面上,而不是所有页面。下面是呈现PDF页面的代码片段。我在网上看到了很多帖子,但都在某种程度上失败了。我也不太熟悉核心图形 CGImageRef imageRef = NULL; CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); CGBitm

我使用核心图形,CGContextDrawPDFPage函数渲染PDF。我试图在图像视图中显示PDF页面。这些页面呈现得非常完美。但有些页面的方向不正确。有些是颠倒过来的。这种情况只发生在少数PDF/页面上,而不是所有页面。下面是呈现PDF页面的代码片段。我在网上看到了很多帖子,但都在某种程度上失败了。我也不太熟悉核心图形

CGImageRef imageRef = NULL;
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bmi = (kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst);
CGContextRef context = CGBitmapContextCreate(NULL, target_w, target_h, 8, 0, rgb, bmi);

if (context != NULL) {

    CGRect thumbRect = CGRectMake(0.0f, 0.0f, target_w, target_h);
    CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 1.0f);
    CGContextFillRect(context, thumbRect);
    CGContextSetRenderingIntent(context, kCGRenderingIntentDefault);

    CGRect mediaRect = CGPDFPageGetBoxRect(thePDFPageRef, kCGPDFCropBox);
    CGContextScaleCTM(context, target_w / mediaRect.size.width, target_h / mediaRect.size.height);
    CGContextTranslateCTM(context, -mediaRect.origin.x, -mediaRect.origin.y);

    CGContextDrawPDFPage(context, thePDFPageRef);
    imageRef = CGBitmapContextCreateImage(context);
    CGContextRelease(context);
}

CGColorSpaceRelease(rgb);

if (imageRef != NULL) {

     UIImage *image = [UIImage imageWithCGImage:imageRef scale:UIScreen.mainScreen.scale orientation:UIImageOrientationUp];
     CFRelease(imageRef);
 }

请给我推荐一种完美的pdf渲染方法。

我不确定这是否对您有帮助,因为我不完全确定您想在pdf中捕获什么

然而,当我这样做的时候,我需要从我的webview中生成pdf。为此,你需要

#import <QuartzCore/QuartzCore.h>

有人能解释一下吗?谢谢
        CGRect frame = myWebView.frame;
        frame.size.height = 1;
        myWebView.frame = frame;
        CGSize fittingSize = [myWebView sizeThatFits:CGSizeZero];
        frame.size = fittingSize;
        myWebView.frame = frame;

        UIGraphicsBeginImageContextWithOptions(fittingSize, YES, 2);
        [myWebView.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        UIImageView *myImg = [[UIImageView alloc] initWithImage:viewImage];
        NSMutableData *pdfData = [NSMutableData data];

        UIGraphicsBeginPDFContextToData(pdfData, myImg.bounds, nil);
        UIGraphicsBeginPDFPage();

        [myImg.layer renderInContext:UIGraphicsGetCurrentContext()];

        UIGraphicsEndPDFContext();