【发布时间】:2015-01-06 05:05:40
【问题描述】:
我使用此代码从我的 UITableView 创建一个 PDF 文件:
var priorBounds:CGRect = self.tableView.bounds;
var fittedSize:CGSize = self.tableView.sizeThatFits(CGSizeMake(priorBounds.size.width, self.tableView.contentSize.height))
self.tableView.bounds = CGRectMake(0, 0, fittedSize.width, fittedSize.height);
var pdfPageBounds:CGRect = CGRectMake(0, 0, 792, 612); // Change this as your need
var pdfData = NSMutableData()
UIGraphicsBeginPDFContextToData(pdfData, pdfPageBounds, nil)
for var pageOriginY:CGFloat = 0; pageOriginY < fittedSize.height; pageOriginY += pdfPageBounds.size.height {
UIGraphicsBeginPDFPageWithInfo(pdfPageBounds, nil);
CGContextSaveGState(UIGraphicsGetCurrentContext());
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0, -pageOriginY)
self.tableView.layer.renderInContext(UIGraphicsGetCurrentContext())
}
UIGraphicsEndPDFContext();
self.tableView.bounds = priorBounds; // Reset the tableView
let path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString
var pdfFileName = path.stringByAppendingPathComponent("testfilewnew.pdf")
pdfData.writeToFile(pdfFileName, atomically: true)
它工作正常,但 PDF 填写了我的 PDF 的整个页面。我想为每个页面添加一个填充,例如标题(在第一页上)和页脚。
我是使用此 PDF 导出的新手,我无法找到解决该问题的方法。谁能帮助我,或带我走向正确的方向?
任何帮助将不胜感激。
【问题讨论】:
-
你有办法解决这个问题吗?
标签: ios uitableview pdf swift