【问题标题】:iOS draw the table in pdf documentiOS在pdf文档中绘制表格
【发布时间】:2011-10-19 12:10:55
【问题描述】:

我将从 UIViewController 的内容创建 pdf。 当 UIViewController 有表格区域时(和 Excel 一样),我在 pdf 文档中没有找到绘制表格的方法。 有谁知道解决这个问题?请帮帮我。

【问题讨论】:

    标签: iphone ios pdf


    【解决方案1】:

    据我所知,如果您使用的是 Quartz 图形上下文(CGContextRef 类型),则没有简单的方法可以创建表。我能够通过在嵌套的 for 循环中在 PDF 上绘制线条并通过仔细注意间距以使其看起来正确来以编程方式创建表格。

    伪代码:

    for (int i=0; i < numberOfRows; i++)
    {
    // display each row
        // Draw row line
        CGPoint horizontalRowDivider[2] = {CGPointMake(x_startPoint, y_startPoint + (i * row_width)), CGPointMake(x_endPoint, y_endPoint + (i * row_width))};
        CGContextStrokeLineSegments(pdfContext, newlineItemDivider, 2);
    
    
        for(int j = 0; j < numberOfColumns; j++)
        {
             //Draw each column cell
             const char *desc_text = "Table value"
             CGContextShowTextAtPoint (pdfContext, x_cellDataLoc, y_cellDataLoc, desc_text, strlen(desc_text));
             CGPoint verticalLineCellDivider[2] = {CGPointMake(x_startPoint + (j * col_width), y_startPoint), CGPointMake(x_endPoint + (j * col_width), y_endPoint)};
             CGContextStrokeLineSegments(pdfContext, verticalLineCellDivider, 2);  
        }
    
    
    }
    

    这是您绘制表格时可能使用的逻辑类型的粗略示例。您可能需要在桌子周围设置一个矩形或边框以使其看起来正确,以及任何其他类型的调整以使其成为您想要的样子。您可以通过以下链接找到有关如何执行此操作的方法列表以及更多信息。我知道这可能不是您的想法,但是如果您完全陷入困境,我希望这可以为您提供一些指导。祝你好运!

    您可以在 Apple 的文档中找到可用于绘制 PDF 的完整函数库:http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html

    【讨论】:

      猜你喜欢
      • 2014-08-11
      • 1970-01-01
      • 2012-08-22
      • 1970-01-01
      • 2011-05-17
      • 2010-11-21
      • 1970-01-01
      • 1970-01-01
      • 2012-04-22
      相关资源
      最近更新 更多