我在创建多页PDF时遇到问题。我正在使用NSData存储PDF数据。 生成PdfData需要2分钟以上。 它在ios 10中显示以下错误
<Error>: replacing +/-infinity with -2147483647.
<Error>: replacing +/-infinity with 2147483648.
<Error>: replacing +/-infinity with -2147483647.
<Error>: replacing +/-infinity with 2147483648.
<Error>: replacing +/-infinity with -2147483647.
<Error>: replacing +/-infinity with 2147483648.
<Error>: replacing +/-infinity with -2147483647.
<Error>: replacing +/-infinity with 2147483648.
无法找到解决方案请帮助我...
生成PDF的代码
-(NSData *)getPdf:(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;
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);
// - page# setup
UILabel *refnoLabel = (UILabel *)[tableView viewWithTag:8888];
int pageno=0;
{
// do page1 separately
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;
}