I would like to create a PDF from a UITableView in Swift. Ill found some tutorials for Objective C, and tried it out but there is still no file generated by this code.
// get a temprorary filename for this PDF
var path = NSTemporaryDirectory();
var pdfFilePath = path.stringByAppendingPathComponent("mypdfdocument.pdf")
UIGraphicsBeginPDFContextToFile(pdfFilePath, CGRectMake(0, 0, self.tableView.contentSize.width, self.tableView.contentSize.height), nil)
UIGraphicsBeginPDFPage();
self.view.layer.renderInContext(UIGraphicsGetCurrentContext())
self.tableView.scrollRectToVisible(CGRectMake(0, 0, 1, 1), animated: false)
self.tableView.layer.renderInContext(UIGraphicsGetCurrentContext())
var screensInTable = Int(self.tableView.contentSize.width) / Int(self.tableView.contentSize.height)
for i in 1...screensInTable {
var point = CGFloat(CGFloat(i) * self.tableView.bounds.height)
var contentOffset:CGPoint = CGPointMake(0, point)
self.tableView.setContentOffset(contentOffset, animated: false)
self.tableView.layer.renderInContext(UIGraphicsGetCurrentContext())
}
UIGraphicsEndPDFContext();
And: I have a Table with 4 Sections and different Row Heights and Cell Templates. Is there a Chance that the generated PDF easily with this type of code? Or would it be better to create Row by Row with CoreText?
Thanks in advance.