【问题标题】:iOS create pdf from UIWebview contentiOS从UIWebview内容创建pdf
【发布时间】:2015-08-08 11:58:58
【问题描述】:

在我的 iOS 应用程序中,我需要从我的 webview 内容创建一个 pdf 文档。我看了这些帖子:Creating PDF file from UIWebViewhttps://coderchrismills.wordpress.com/2011/06/25/making-a-pdf-from-a-uiwebview/

我想知道是否有更简单的方法可以做到这一点。例如,对于我的 Mac 项目,我使用这个:

NSData *pdf = [[[[webView mainFrame] frameView] documentView] dataWithPDFInsideRect:[[[webView mainFrame] frameView] documentView].frame];
PDFDocument *doc = [[PDFDocument alloc] initWithData:pdf];

在 iOS 中是否有任何简单的方法可以做到这一点?

从 webview 内容中获取最佳质量的 pdf 文档的最佳选择是什么?

【问题讨论】:

标签: ios pdf uiwebview


【解决方案1】:

没有一种方法可以像在 Mac 上那样直接通过 SDK 实现这一点,但是您可能希望查看BNHtmlPdfKit,它允许您将 URL、Web 视图和 html 字符串的内容保存为PDF。

例如如下:

self.htmlPdfKit = [BNHtmlPdfKit saveUrlAsPdf:[NSURL URLWithString:@"http://itsbrent.net"] toFile:@"...itsbrent.pdf" pageSize:BNPageSizeA6 success:^(NSString *pdfFileName) {
    NSLog(@"Done");
} failure:^(NSError *err) {
    NSLog(@"Failure");
}];

它使用自定义的UIPrintPageRenderer 覆盖paperRectprintableRect,从而导致UIPrintFormatter 返回pageCount 并呈现文档。

【讨论】:

    【解决方案2】:

    我在 AnderCover 找到了很好的答案 "Creating PDF file from UIWebView" 它也没有使用任何第三方 api。从 webview 创建 pdf。

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-24
      • 2013-03-26
      • 2023-03-18
      • 2015-03-17
      • 2017-07-27
      • 1970-01-01
      • 1970-01-01
      • 2011-11-22
      相关资源
      最近更新 更多