IOS中将UIScrollView转换保存成PDF文件数据
下面方法 返回一个NSData类型 之后 [pdfData writeToFile:documentDirectoryFilename atomically:YES]; 就ok了 代码不贴了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
- (NSMutableData*)createPDFfromUIScrollView:(UIScrollView*)scrollView{ NSMutableData *pdfData = [NSMutableData data]; UIGraphicsBeginPDFContextToData(pdfData, (CGRect){0,0, scrollView.contentSize}, nil); UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, scrollView.contentSize.width,scrollView.contentSize.height), nil); CGContextRef pdfContext = UIGraphicsGetCurrentContext(); CGRect origSize = scrollView.frame; CGRect newSize = origSize; newSize.size = scrollView.contentSize; [scrollView setFrame:newSize]; [scrollView.layer renderInContext:pdfContext]; [scrollView setFrame:origSize]; UIGraphicsEndPDFContext(); return pdfData; } |
转载请注明:天狐博客 » iOS中将UIScrollView转换保存成PDF文件数据