【问题标题】:CGPDFContextCreateWithURL not correctly creating contextCGPDFContextCreateWithURL 未正确创建上下文
【发布时间】: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

在控制台中显示: &lt;Error&gt;: CGPDFContextCreate: failed to create PDF context delegate.

我已经尝试了几种不同的路径,所以我相当确定这不是问题所在。感谢您的建议!

【问题讨论】:

    标签: iphone objective-c pdf cgpdfcontext


    【解决方案1】:

    如果你的字符串包含路径,你需要 +[NSURL fileURLWithPath:],而不是 +[NSURL URLWithString:]。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-02
      • 2016-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多