scrollerView转PDF

2017-09-05  本文已影响0人  开洋_shen

-(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;

}

NSMutableData *data = [self createPDFfromUIScrollView:self.textView];

NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/testFile.pdf"]];

上一篇下一篇

猜你喜欢

热点阅读