I want to create pdf in the document directory and want to provide page numbers, so I need a CGPDFDocumentRef object.
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)
I converted the file path to url, but this line below causes crashes, and I don't know why ..?
let pdfDocumentRef: CGPDFDocumentRef = CGPDFDocumentCreateWithURL(localUrl as CFURLRef)!
source share