我有一个简单的函数来创建 pdf 文件并返回它的路径。
func createPDFFileAndReturnPath() -> String {
let fileName = "pdffilename.pdf"
let paths = NSSearchPathForDirectoriesInDomains(.LibraryDirectory, .UserDomainMask, true)
let documentsDirectory = paths[0]
let pathForPDF = documentsDirectory.stringByAppendingString("/" + fileName)
UIGraphicsBeginPDFContextToFile(pathForPDF, CGRectZero, nil)
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 100, 400), nil)
let text = "text" //how to print this in whatever place?
//text.drawInRect - this doesn't work
UIGraphicsEndPDFContext()
return pathForPDF
}