我试图基本了解如何在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字节。
你们给予的任何帮助都将非常感激。欢呼声。
答案 0 :(得分:2)
您可以使用UIWebView阅读pdf或DocumentPreviewController。