关于如何使用SimplePDF,我遇到了一个问题。
当我按下一个简单的UIButton时,我想从我的应用程序中导出PDF文件。
现在,我尝试使用SimplePDF提供的标准代码,但仍然有问题:
代码:
let a4PaperSize = CGSize(width: 210, height: 297)
let pdf = SimplePDF(pageSize: a4PaperSize)
pdf.setContentAlignment(.center)
// add logo image
let logoImage = UIImage(named:"train-icon180.png")!
pdf.addImage(logoImage)
// [...]
// Generate PDF data and save to a local file.
// Here is where I've got a problem
if let documentDirectories = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first {
let fileName = "\(ReceptionOuvertureLigne).pdf"
let documentsFileName = documentDirectories + "/" + fileName
let pdfData = pdf.generatePDFdata()
do{
try pdfData.writeToFile(documentsFileName, options: .DataWritingAtomic)
print("\nThe generated pdf can be found at:")
print("\n\t\(documentsFileName)\n")
}catch{
print(error)
}
实际上,PDF生成部分中的行:try pdfData.writeToFile(documentsFileName, options: .DataWritingAtomic)
是由错误引起的:
Value of type 'Data' has no member 'writeToFile'
我不知道该怎么解决...