Ever since iOS 10, I have started having this issue. I had researched and it seems others also have this issue,
Can anyone else confirm this persists in iOS 10.2? Some have said that it was fixed in 10.2 but it still occurs on my source code.
https://twitter.com/steipete/status/764446752472698880
Can anyone else confirm this persists in iOS 10.2? Some have said that it was fixed in 10.2 but it still occurs on my source code.
https://twitter.com/steipete/status/764446752472698880
Code:
-(NSData *)getPdfSimpleSO:(UITableView *)tableView{
// -- first page height, rest pages height: adjust to get it right
#define FIRST_PAGE_HEIGHT 1160
#define REST_PAGES_HEIGHT 1130
CGSize fittedSize;
CGRect savedFrame = tableView.frame;
CGRect priorBounds = tableView.frame;
priorBounds.size.width=768; // put into Portrait
tableView.frame = priorBounds;
fittedSize = [tableView sizeThatFits:CGSizeMake(priorBounds.size.width, ([tableView numberOfRowsInSection:0] * 49) + 829)];
tableView.bounds = CGRectMake(0, 0, fittedSize.width, fittedSize.height);
CGRect pdfPageBounds;
// Standard US Letter dimensions 8.5" x 11"
pdfPageBounds = CGRectMake(0, -15, 768, REST_PAGES_HEIGHT);
NSMutableData *pdfData = [[NSMutableData alloc] init];
UIGraphicsGetCurrentContext();
UIGraphicsBeginPDFContextToData(pdfData, pdfPageBounds, nil);
// 140209b dan - page# setup
UILabel *refnoLabel = (UILabel *)[tableView viewWithTag:8888];
int pageno=0;
{
// do page1 separately due to Order Header (customer info, etc.)
CGRect pdfPageBoundsPage1 = CGRectMake(0,0,768, FIRST_PAGE_HEIGHT+15);
UIGraphicsGetCurrentContext();
UIGraphicsBeginPDFPageWithInfo(pdfPageBoundsPage1, nil);
{
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 10, 0);
[tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
[@"Page 1" drawAtPoint:CGPointMake(340.0, 10.0)
withAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:24],NSForegroundColorAttributeName:[UIColor blackColor]}];
pageno ++;
}
// start from 2nd page
for (CGFloat pageOriginY = FIRST_PAGE_HEIGHT; pageOriginY < fittedSize.height; pageOriginY += REST_PAGES_HEIGHT)
{
UIGraphicsBeginPDFPageWithInfo(pdfPageBounds, nil);
{
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 10, -pageOriginY+15);
[tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
NSString *pageString = [NSString stringWithFormat:@"Ref#:%@ Page %i", refnoLabel.text, pageno+1 ];
[pageString drawAtPoint:CGPointMake(330, REST_PAGES_HEIGHT * pageno +30)
withAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetica"
size:14]}];
pageno ++;
}
}
}
UIGraphicsEndPDFContext();
tableView.bounds = priorBounds;
// 140208 dan - Comment: restored the saved WIDTH
tableView.frame=savedFrame ;
return pdfData;
}
Last edited: