ios - 在下载文件夹文件应用程序中将 tableview 保存为 PDF 问题 | 迅速
问题描述
我目前有一个 UITableViewController 显示我希望可以选择保存为 PDF 并稍后打印的信息。
目前我有以下功能,但我不知道它保存文件的位置,我可以从下载下的文件应用程序中轻松访问它:
func pdfDataWithTableView(tableView: UITableView) {
let priorBounds = tableView.bounds
let fittedSize = tableView.sizeThatFits(CGSize(width:priorBounds.size.width, height:tableView.contentSize.height))
tableView.bounds = CGRect(x:0, y:0, width:fittedSize.width, height:fittedSize.height)
let pdfPageBounds = CGRect(x:0, y:0, width:tableView.frame.width, height:self.view.frame.height)
let pdfData = NSMutableData()
UIGraphicsBeginPDFContextToData(pdfData, pdfPageBounds,nil)
var pageOriginY: CGFloat = 0
while pageOriginY < fittedSize.height {
UIGraphicsBeginPDFPageWithInfo(pdfPageBounds, nil)
UIGraphicsGetCurrentContext()!.saveGState()
UIGraphicsGetCurrentContext()!.translateBy(x: 0, y: -pageOriginY)
tableView.layer.render(in: UIGraphicsGetCurrentContext()!)
UIGraphicsGetCurrentContext()!.restoreGState()
pageOriginY += pdfPageBounds.size.height
}
UIGraphicsEndPDFContext()
tableView.bounds = priorBounds
var docURL = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)).last! as URL
docURL = docURL.appendingPathComponent("myDocument.pdf")
pdfData.write(to: docURL as URL, atomically: true)
}
解决方案
推荐阅读
- spring-boot - 如何在spring webflux中的webClient实例化期间设置一次访问令牌?
- python - __init__() 调用类时缺少位置参数
- html - html下拉列表加载第一个值
- python - 模型未在 Django 模板中呈现
- python - [Django]提交表单后如何在不刷新页面的情况下显示消息(正确或错误)?
- amazon-web-services - 如何使用 proxy+ 处理 api 网关上的根资源以返回正文?
- python - 关于如何停止我的按钮点击 tkinter 的问题?
- python - 从熊猫数据框中将所有列放入单个系列中
- javascript - 使用 fs (javascript) 将数据写入文件时遇到问题
- python - 在 Pandas 中查看 Stata 变量标签