5

ドキュメントディレクトリに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)!
4

3 に答える 3

0
 let localUrl  = pdfPathWithFileName as CFStringRef
 let pdfDocumentRef = CFURLCreateWithFileSystemPath(nil, localUrl, CFURLPathStyle.CFURLPOSIXPathStyle, false)
 let page_count = CGPDFDocumentGetNumberOfPages(pdfDocumentRef)
于 2016-05-04T07:47:01.020 に答える
0

あなたtest.pdfがドキュメントディレクトリフォルダに存在しないためです。

于 2016-05-04T06:53:57.293 に答える