我想在文档目录中创建 pdf 并想给出页码,所以我需要 CGPDFDocumentRef 对象。
let fileName: NSString = "test.pdf"
let path:NSArray = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let documentDirectory: AnyObject = path.objectAtIndex(0)
let pdfPathWithFileName = documentDirectory.stringByAppendingPathComponent(fileName as String)
UIGraphicsBeginPDFContextToFile(pdfPathWithFileName as String, CGRectZero, nil)
let ref : CGContextRef = UIGraphicsGetCurrentContext()!
let localUrl = NSURL.fileURLWithPath(pdfPathWithFileName)
我已经在 url 中转换了文件路径,但是下面这行会产生崩溃,我不知道为什么..?
let pdfDocumentRef: CGPDFDocumentRef = CGPDFDocumentCreateWithURL(localUrl as CFURLRef)!