ios save web page as pdf

前端 未结 1 1245
日久生厌
日久生厌 2021-01-14 02:58

Can someone point me in the right direction for saving a webpage as a pdf? I already have a library for an iOS pdf reader, but I need to somehow implement a feature for savi

相关标签:
1条回答
  • 2021-01-14 03:26

    This is not something that I have done, but it seems you are not the first to want to do something like this.

    http://www.iphonedevsdk.com/forum/iphone-sdk-development/21451-save-contents-uiwebview-pdf-file.html

    The last post in this link provides code to save a UIWebView as an image, and you should be able to convert that image into a PDF. I don't take credit for the code as I did not write it, just connecting you two :)

    Here is the code for simplicity:

    CGSize sixzevid=CGSizeMake(1024,1100);
    UIGraphicsBeginImageContext(sixzevid);
    [webview.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    NSData *imageData = UIImagePNGRepresentation(viewImage);
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *pathFloder = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@",@"new.png"]];
    NSString *defaultDBPath = [documentsDirectory stringByAppendingPathComponent:pathFloder];
    
    
    [imageData writeToFile:defaultDBPath atomically:YES];
    

    Chances are pretty good that you will have to tweak this but, hopefully this helps you move in the right direction.

    0 讨论(0)
提交回复
热议问题