Add UIImage at End of PDF

Add UIImage at End of PDF

I used Apple's documentation to create a Multi-page PDF. I need to place a
UIImage underneath the text that is rendered in the PDF. Here's what I
have so far:
UIGraphicsBeginPDFContextToFile(pdfFileName, CGRectZero, nil);
pageSize = CGSizeMake(612, 792);
CFRange currentRange = CFRangeMake(0, 0);
NSInteger currentPage = 0;
BOOL done = NO;
do {
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width,
pageSize.height), nil);
currentPage++;
[self drawPageNumber:currentPage];
[self drawHeader];
currentRange = [self renderPage:currentPage
withTextRange:currentRange andFramesetter:framesetter];
// If we're at the end of the text, exit the loop.
if (currentRange.location ==
CFAttributedStringGetLength((CFAttributedStringRef)currentText))
done = YES;
}
while (!done);
Then, I add an image in a separate PDF page:
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width,
pageSize.height), nil);
currentPage++;
[self drawPageNumber:currentPage];
[self drawHeader];
[self drawImages];
// Close the PDF context and write the contents out.
UIGraphicsEndPDFContext();
However, if there is very little text on the PDF that is created, there
will be a lot of unfilled white space. I need to place the image at the
bottom of the current PDF if there is space, and create a new PDF if not.
So, I need to check for a "y" position of the text.
How would I do that?