I’m trying to basically understand how a simple PDF is created and turned into a UIImage on the iPhone. I have cobbled together this code:
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]
I am fairly certain that this code is correct, aside from the last line (which is incorrect because UIImage cannot read PDF data), so I’m trying to find out which class I can send my PDF into.
‘pdfData’ is not nil, it is about 5000 bytes in size.
Any help you guys can give will be much appreciated. Cheers.
You can use UIWebView to read pdf or DocumentPreviewController.