2
我必须从UITableView
生成具有多个节和行的PDf。从表视图中生成PDF时发生的问题
我已经生成的PDF很好,但问题是在创建PDF它正在削减某些行的数据,并显示其他网页上。
所以请建议任何动态逻辑,这将有助于在页面上创建具有数据的PDf而无需转到其他页面。
另请参阅下面我用来创建PDF的代码。
CGRect priorBounds = self.tableView.bounds;
CGSize fittedSize = [self.tableView sizeThatFits:CGSizeMake(priorBounds.size.width, self.tableView.contentSize.height)];
self.tableView.bounds = CGRectMake(0, 0, 612, fittedSize.height);
CGRect pdfPageBounds = CGRectMake(0, 0, 612, 792); // Change this as your need
NSMutableData *pdfData = [[NSMutableData alloc] init];
UIGraphicsBeginPDFContextToData(pdfData, pdfPageBounds, nil); {
for (CGFloat pageOriginY = 0; pageOriginY < fittedSize.height; pageOriginY += pdfPageBounds.size.height) {
UIGraphicsBeginPDFPageWithInfo(pdfPageBounds, nil);
CGContextSaveGState(UIGraphicsGetCurrentContext()); {
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0, -pageOriginY);
[self.tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
} CGContextRestoreGState(UIGraphicsGetCurrentContext());
}
} UIGraphicsEndPDFContext();
self.tableView.bounds = priorBounds; // Reset the tableView
// Use the pdfData to
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
//Get the docs directory
NSString *filePathPDF = [documentsPath stringByAppendingPathComponent:@"image.pdf"]; //Add the file name
[pdfData writeToFile:filePathPDF atomically:YES];
任何帮助将不胜感激。
请提出解决方案.... – user1487846
这个任何解决方案?我陷入了同样的问题。 – Jorge