iOS在pdf文档中绘制表格 [英] iOS draw the table in pdf document

查看:89
本文介绍了iOS在pdf文档中绘制表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将从UIViewController的内容创建pdf. 当UIViewController具有表区域(与Excel相同)时,我没有找到在pdf文档中绘制表的方法. 有谁知道解决这个问题?请帮助我.

I will create the pdf from the contents of UIViewController. When UIViewController has a table region(the same as Excel), I didn't find the method for drawing an table in pdf document. Does anyone know to solve this problem? Please help me.

推荐答案

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

There is no easy method of creating a table I know of if you're using a Quartz graphics context (CGContextRef type). I was able to create a table programmatically by drawing lines on the PDF in nested for loops, and by paying careful attention to spacing to make it look right.

伪代码:

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);  
    }


}

这是您可以用来绘制表格的逻辑类型的粗略示例.您可能希望在桌子周围有一个矩形或边框以使其看起来正确,以及进行其他各种调整以使其达到您想要的效果.您可以通过以下链接找到有关操作方法的列表以及更多信息.我知道这可能与您的想法无关,但是我希望这为您提供了一些方向,如果您完全陷入困境的话.祝你好运!

This is a rough example of the kind of logic you might use to draw a table. You'll probably want a rectangle, or a border, around your table to make it look right, among any other kinds of tweaks to make it how you want. You can find the list of methods on how to do that and more through the below link. I know this probably isn't what you had in mind, but I hope this gives you some direction to take if you were totally stuck. Good luck!

您可以在Apple文档中找到可用于绘制PDF的完整功能库:

You can find the full library of functions available for drawing PDFs in Apple's documentation: http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html

这篇关于iOS在pdf文档中绘制表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆