【问题标题】:ios save web page as pdfios将网页另存为pdf
【发布时间】:2011-10-27 07:54:49
【问题描述】:

有人能指出我将网页保存为 pdf 的正确方向吗?我已经有一个 iOS pdf 阅读器的库,但我需要以某种方式实现一个功能,用于将用户正在查看的任何网页保存为 pdf。我假设我必须使用应用内浏览器。有什么想法吗?

【问题讨论】:

    标签: iphone ios ipad pdf


    【解决方案1】:

    这不是我做过的事情,但似乎你不是第一个想要做这样的事情的人。

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

    此链接中的最后一篇文章提供了将 UIWebView 保存为图像的代码,您应该能够将该图像转换为 PDF。我不认为代码是我写的,只是把你们两个联系起来:)

    为了简单起见,这里是代码:

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

    很有可能您必须对此进行调整,但希望这可以帮助您朝着正确的方向前进。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-07
      相关资源
      最近更新 更多