我正在尝试在Objective-C中以编程方式创建PDF文件,随着我的数据越来越大,我需要继续在第二页上绘制它。通过使用下一个代码,我能够创建必要数量的页面,但内容仅在第一个页面上绘制。关于我应该改变什么的任何建议?
+(void)drawPDF:(NSString*)fileName
{
// Create the PDF context using the default page size of 612 x 792.
UIGraphicsBeginPDFContextToFile(fileName, CGRectZero, nil);
// Mark the beginning of a new page.
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);
int currentPage = 1;
for (int count = 30; count < 3000; count = count + 100) {
//add new PDF page if the content doesn't fits on the curent one
if (currentPage * 792 < count + 30) {
currentPage ++;
UIGraphicsBeginPDFPage();
}
[self drawCellFromStartingPoint:count];
}
// Close the PDF context and write the contents out.
UIGraphicsEndPDFContext();
}
答案 0 :(得分:0)
UIGraphicsBeginPDFContextToFile(...);
UIGraphicsBeginPDFPageWithInfo(...); // start first page
UIGraphicsBeginPDFPageWithInfo(...); // start second page
UIGraphicsEndPDFContext();
请参阅this answer了解详情。
希望这会有所帮助:)
答案 1 :(得分:0)
问题是我正在继续从当前计算的Y位置(来自for循环的计数值)绘制数据,所以为了使其正常工作,我必须重置每页上的Y值,所以在最后我调整了这条线:
[self drawCellFromStartingPoint:count];
工作为:
[self drawCellFromStartingPoint:count - ((currentPage - 1) * 792)];