我想基本上了解如何創建一個簡單的PDF,並轉化爲iPhone上的UIImage。我曾經拼湊驗證碼:如何繪製PDF NSData到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'不是零,它大小約爲5000字節。
任何幫助你們可以給予非常感謝。乾杯。
傳遞給'UIGraphicsBeginPDFContextToData()'的邊界不應該是'CGRectZero'嗎? –
將CGRectZero賦予此函數可爲上下文提供(0,0,612,792)的默認邊界。 – Dyldo42