2010-03-23 5 views
1

다음 코드를 사용하면 ctx가 제대로 만들어지지 않습니다. 그것은 nil 남아 :CGPDFContextCreateWithURL에서 컨텍스트를 제대로 만들지 못했습니다.

#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 

그것을 보여줍니다 콘솔에서 : 나는 그게 문제가되지 않습니다 확신한다 그래서 여러 가지 경로를 시도했습니다 <Error>: CGPDFContextCreate: failed to create PDF context delegate.

. 어떤 조언을 주셔서 감사합니다!

답변

1

문자열에 경로가 포함되어 있으면 + [NSURL URLWithString :]이 아닌 + [NSURL fileURLWithPath :]가 필요합니다.