CGPDFContextCreateWithURL 未正确创建上下文
使用以下代码,未正确创建 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
在控制台中它显示:
我尝试了几种不同的路径,所以我相当确定这不是问题。感谢您的任何建议!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果字符串包含路径,则需要 +[NSURL fileURLWithPath:],而不是 +[NSURL URLWithString:]。
If your string contains a path, you want +[NSURL fileURLWithPath:], not +[NSURL URLWithString:].