iOS在pdf文档中绘制表格

发布于 2024-12-10 21:15:35 字数 111 浏览 0 评论 0原文

我将从 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

极度宠爱 2024-12-17 21:15:35

据我所知,如果您使用 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

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.

Psuedo-code:

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!

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文