【问题标题】:Create pdf file from UITableView从 UITableView 创建 pdf 文件
【发布时间】:2011-10-08 16:07:30
【问题描述】:

我正在阅读 this threadthis article

我的问题是如何将内容从我的视图中获取到 CreateMethod。在文章中它有这样的调用:

NSString *content = textView.text; //this is the UITextView, containing our text.

由于我使用的是 UITable 视图,如何获取内容。 . .实际上,我也想获得包含表格前所有信息的整个视图。

有什么想法,或者至少是朝着正确的方向推进?

【问题讨论】:

    标签: ios xcode uitableview pdf pdf-generation


    【解决方案1】:

    您可以将 UITableView 绘制为 图像 - 这可能不太好(您可能想要文本),但这会相对便宜。这只是一个骨架,以了解这个想法:

    if (!UIGraphicsBeginPDFContextToFile(newFilePath, page, metaData )) {
        NSLog(@"error creating PDF context");
        return;
    }
    
    UIGraphicsBeginPDFPage();
    [tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIGraphicsEndPDFContext();
    

    【讨论】:

    • 这会抓取所有的表格视图还是只抓取屏幕上的内容?
    • 谢谢。我很感激,但我需要抓取整个表格(这是发票和发票详细信息。)
    【解决方案2】:

    [tableView.layer renderInContext:UIGraphicsGetCurrentContext()];

    它渲染表格视图并获取所有表格视图并制作表格视图的 pdf。

    【讨论】:

      猜你喜欢
      • 2017-11-03
      • 2013-03-26
      • 1970-01-01
      • 2011-02-03
      • 2015-01-29
      • 2017-05-22
      • 2022-09-25
      • 2013-03-17
      • 2011-05-25
      相关资源
      最近更新 更多