iOS - 在表中绘制文本,如PDF格式的结构

时间:2014-06-12 13:16:18

标签: ios objective-c pdf core-text

我正在尝试创建如下图像的pdf。我用NSString *tempStr = [NSString stringWithFormat:@" %@ %@ %@ %@ \n",monthsInfo.month,monthsInfo.principal,monthsInfo.interest,monthsInfo.balance];创建了字符串 我只是为每一行循环这个代码并构造一个字符串。

enter image description here

我用代码

获得了pdf
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);

                // Draw a page number at the bottom of each page.
                currentPage++;
                [self drawPageNumber:currentPage];

                // Render the current page and update the current range to
                // point to the beginning of the next page.
                currentRange = [self renderPage:1 withTextRange:currentRange andFramesetter:framesetter];

我得到了如下图所示的pdf,我发现格式问题,任何人都可以帮我构建这个pdf,或者请给出你的建议我需要采取哪种方法来正确构建它。

enter image description here

1 个答案:

答案 0 :(得分:0)

在某些字体中,您有不同的字符宽度。这样你永远不会得到一个直列。一种方法是使用具有相同字符宽度的等宽字体。 也许Tab" \ t"也会工作。无论如何它比空间更好。

相关问题