CGPDFContextCreateWithURL not correctly creating context

Posted by mjdth on Stack Overflow See other posts from Stack Overflow or by mjdth
Published on 2010-03-23T20:42:00Z Indexed on 2010/03/23 20:43 UTC
Read the original article Hit count: 453

Filed under:
|
|
|

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: failed 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!

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone