开发者

CGPDFContextCreateWithURL not correctly creating context

Using the following code, the ctx is not correctly being created. It remains nil:

#import <QuartzCore/QuartzCore.h>

@implementation UIView(PDFWritingAdditions)

- (void)renderInPDFFile:(NSString*)path
{
    CGRect mediaBox = self.bounds;
    CGContextRef ctx = CGPDFContextCreateWithURL((CFURLRef)[NSURL URLWithString:path], &mediaBox, NULL);

    CGPDFContextBeginPage(ctx, NULL);
    CGContextScaleCTM(ctx, 1, -1);
    CGContextTranslateCTM(ctx, 0, -mediaBox.size.height);
    [self.layer renderInContext:ctx];
    CGPDFContextEndPage(ctx);
    CFRelease(ctx);
}

@end

In the console it shows: <Error>: CGPDFContextCreate: fail开发者_Python百科ed to create PDF context delegate.

I've tried several different paths so I'm fairly certain that is not the problem. Thanks for any advice!


If your string contains a path, you want +[NSURL fileURLWithPath:], not +[NSURL URLWithString:].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜