gpt4 book ai didi

objective-c - 将图像绘制为 PDF

转载 作者:行者123 更新时间:2023-12-03 17:53:01 24 4
gpt4 key购买 nike

我想将整页图像绘制为 PDF,但我总是很难理解 CGContextRef,所以我不知道如何处理该错误.

请注意,这不是 iOS。我正在制作一个桌面应用程序。

到目前为止,我有这个:

-(void) addImage:(NSURL*) url toPage:(size_t) page toPDF:(CGPDFDocumentRef) pdf
{
NSImage *image = [[NSImage alloc] initWithContentsOfURL:url];
image = [image imageScaledToFitSize:pageSize.size]; //From Matt Gemmell's Crop extensions category

[image lockFocus];

CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
[image drawInRect:pageSize];
[image unlockFocus];


CGPDFPageRef pageRef = CGPDFDocumentGetPage(pdf, page);

CGPDFContextBeginPage(context, pageInformation);
CGContextDrawPDFPage(context, pageRef);
CGPDFContextEndPage(context);
}

但是,我遇到了错误:

CGPDFContextEndPage: invalid context 0x61000017b540. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

请问我的上下文有什么问题吗?

最佳答案

您需要创建并使用CGPDFContext。不同的上下文特定于不同的渲染进程/目的地,因此您需要选择正确的一个。所以看看使用 CGPDFContextCreateWithURL创建 PDF 上下文以将数据写入文件。

关于objective-c - 将图像绘制为 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20166834/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com