美文网首页
scrollerView转PDF

scrollerView转PDF

作者: 开洋_shen | 来源:发表于2017-09-05 19:46 被阅读0次

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

    相关文章

      网友评论

          本文标题:scrollerView转PDF

          本文链接:https://www.haomeiwen.com/subject/qodpjxtx.html