【发布时间】:2011-01-30 23:59:58
【问题描述】:
使用以下代码,未正确创建 ctx。它仍然是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
在控制台中显示:
<Error>: CGPDFContextCreate: failed to create PDF context delegate.
我已经尝试了几种不同的路径,所以我相当确定这不是问题所在。感谢您的建议!
【问题讨论】:
标签: iphone objective-c pdf cgpdfcontext