美文网首页
iOS view转pdf文件

iOS view转pdf文件

作者: 移动的键盘 | 来源:发表于2021-01-27 15:45 被阅读0次
- (void)createPDFfromUIView:(UIView*)aView
{
    NSMutableData *pdfData = [NSMutableData data];
    UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, @{});
    UIGraphicsBeginPDFPage();
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();
    [aView.layer renderInContext:pdfContext];
    UIGraphicsEndPDFContext();
    NSString *pdfPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES).firstObject stringByAppendingPathComponent:@"file.pdf"];
    [pdfData writeToFile:pdfPath atomically:YES];
    NSLog(@"pdfPath: %@",pdfPath);
}

相关文章

网友评论

      本文标题:iOS view转pdf文件

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