0

Please help, I'm trying to create a Multi paged pdf in objective-c based on the objects of an array, the problem is that the first page of the pdf sets out the text of the objects fine, but when it gets to the second page the text begins again towards the bottom of the page, I've tried resetting the newOriginY value but this gets ignored unless I specify for which index of an object, I just want to data to continue onto the second page starting at the top, here is the code:

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

}
Leethal
  • 25
  • 5

1 Answers1

0

As far as I can tell origin.y doesn't change. Meaning that no matter what row you are on it will always be farther down on your page. For example

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

Try something like this

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

}

I hope that helps.

Skyler Lauren
  • 3,792
  • 3
  • 18
  • 30
  • Thank you for your reply, unfortunately this does not resolve the issue as the creating of the next page is not the issue, the issue is resetting the Y parameter of where it is getting printed in the for loop so that printing resumes starting at the top of the next page, because at the moment printing resumes on the bottom of the second page. – Leethal Feb 04 '15 at 23:10
  • Glad to hear it. If this solved your question please mark this answer as accepted. If it wasn't close enough to the actual solution then make sure you add an answer that is so others can learn. – Skyler Lauren Feb 05 '15 at 01:31