在 objective-c 中创建多页 pdf

Creating a multi paged pdf in objective-c

请帮忙,我正在尝试根据数组的对象在 objective-c 中创建一个多页 pdf,问题是 pdf 的第一页很好地列出了对象的文本,但是当它到达第二页时,文本再次开始朝向页面底部,我尝试重置 newOriginY 值,但除非我指定对象的哪个索引,否则这将被忽略, 我只想将数据从顶部开始继续到第二页, 这是代码:

// Table setup
CGRect frame;
int newOriginX = 0;
int newOriginY = 0;

for (int i = 0; i < [allInfo count]; i++){
    NSArray *infoToDraw = [allInfo objectAtIndex:i];

    for (int j = 0; j < numberOfColumns; j++){

        if (j == 1) {
            newOriginX = origin.x + (j * columnWidth + 80);
        }
        else if (j == 3){
            newOriginX = origin.x + (j * columnWidth - 60);
        }
        else{
            newOriginX = origin.x + (j * columnWidth);
        }

        newOriginY = origin.y + ((i + 1) * rowHeight);

        if (i == 12) {
            newOriginY = 0;
            origin.y = 0;
        }

        frame = CGRectMake(newOriginX + padding, newOriginY + padding, columnWidth, rowHeight);

        // Draw the text
        [self drawText:[infoToDraw objectAtIndex:j] inFrame:frame];
    }

    // Create new page
    if (i == 11) {
        UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 44, 540, 600), nil);
    }

}

据我所知 origin.y 没有改变。这意味着无论您在哪一行,它都将始终位于页面的下方。例如

newOriginY = origin.y + ((i + 1) * rowHeight);
//newOriginY = 0 + ((12+1) *rowHeight);

尝试这样的事情

// Table setup
CGRect frame;
int newOriginX = 0;
int newOriginY = 0;

for (int i = 0; i < [allInfo count]; i++){

    NSArray *infoToDraw = [allInfo objectAtIndex:i];

    for (int j = 0; j < numberOfColumns; j++){

        if (j == 1) {
            newOriginX = origin.x + (j * columnWidth + 80);
        }
        else if (j == 3){
            newOriginX = origin.x + (j * columnWidth - 60);
        }
        else{
            newOriginX = origin.x + (j * columnWidth);
        }


        frame = CGRectMake(newOriginX + padding, newOriginY + origin.y, columnWidth, rowHeight);

        // Draw the text
        [self drawText:[infoToDraw objectAtIndex:j] inFrame:frame];

    }

    newOriginY += (rowHeight + padding);

    // Create new page
    if (newOriginY >= 600)
    {
        newOriginY = 0;
        UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 44, 540, 600), nil);
    }

}

希望对您有所帮助。