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