iphone - 如何将 PDF NSData 绘制到 UIImage?

标签 iphone objective-c ios pdf

我试图从根本上了解如何在 iPhone 上创建简单的 PDF 并将其转换为 UIImage。我拼凑了这段代码:

NSMutableData *pdfData = [[NSMutableData alloc] init];
UIGraphicsBeginPDFContextToData(pdfData, CGRectZero, nil);

CFAttributedStringRef currentText = CFAttributedStringCreate(NULL, (CFStringRef)@"Text", NULL);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText);
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);
CGMutablePathRef framePath = CGPathCreateMutable();
CGPathAddRect(framePath, NULL, CGRectMake(0, 0, 612, 792));
CTFrameRef frame = CTFramesetterCreateFrame(framesetter,
                                            CFRangeMake(0, [(NSString *)currentText length]),
                                            framePath,
                                            NULL);

CTFrameDraw(frame, UIGraphicsGetCurrentContext());
UIGraphicsEndPDFContext();
UIImage *pdfImage = [UIImage imageWithData:pdfData]

我相当确定这段代码是正确的,除了最后一行(这是不正确的,因为 UIImage 无法读取 PDF 数据),所以我试图找出我可以将我的 PDF 发送到哪个类。

'pdfData' 不是 nil,它的大小约为 5000 字节。

非常感谢你们能提供的任何帮助。干杯。

最佳答案

您可以使用 UIWebView 阅读 pdf 或 DocumentPreviewController。

关于iphone - 如何将 PDF NSData 绘制到 UIImage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6421092/

相关文章:

ios - 安装配置文件时出现问题

ios - 如何在 Messages Extension 中发送 MSMessage?

iphone - 从 NSMutableArray 中的对象创建 NSArray

ios - iOS 7 上的尺寸等级

ios - 从一个 View Controller 传递字符串并将其显示在 ios 的 UITextView 中

ios - 按字母顺序对 UITableView 内容(地址簿)进行排序

iphone - 更改按钮文本颜色未反射(reflect)

iphone - 我如何在 cocos2d 中交叉淡入淡出音乐?

iphone - iPad旋转锁定问题

iphone - 需要 iPhone 上的风景照片