【发布时间】:2014-04-21 21:56:54
【问题描述】:
我正在使用代码创建 PDF 文件。有效。
但是:我希望我的整个 UITableView(我需要滚动)在我的 PDF 文件中,而不仅仅是当前显示在屏幕上的视图部分。 套索我需要将三个文本字段添加到同一个文件 PDF 这必须取所有视图的内容(三个 textField 和所有单元格的 tableView),因为这是一张发票 有没有办法做到这一点? 我使用以下代码
- (void)saveToDocumentsWithFileName:(NSString*)aFilename;
{
// Creates a mutable data object for updating with binary data, like a byte array
NSMutableData *pdfData = [NSMutableData data];
// Points the pdf converter to the mutable data object and to the UIView to be converted
UIGraphicsBeginPDFContextToData(pdfData, self.view.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
[self.view.layer renderInContext:pdfContext];
// remove PDF rendering context
UIGraphicsEndPDFContext();
// Retrieves the document directories from the iOS device
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
}
但它作为视图的图像和 tableView 的剩余单元格不包含 PDF 文件的问题
【问题讨论】:
-
UIGraphicsBeginPDFContextToData(pdfData, self.tablview.bounds, nil);试试这个。
-
不工作还为现有单元格截屏
标签: ios iphone uitableview pdf-generation core-graphics