从图像iOS生成PDF

时间:2015-01-09 18:18:39

标签: ios swift cgcontext

我正在尝试生成当前已加载到图像视图中的图像的PDF。我认为我的代码是正确的但是当我检查模拟器的文档文件夹时没有弹出任何内容。有任何想法吗? 这是与我的botton链接的代码:

    @IBAction func saveToPdf(sender: AnyObject) {
    var fileName:String = "new.pdf"
    var rect =  CGRectMake(0, 0, 850, 1100)
    var path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask, true)[0] as String
    var pdfPath = path.stringByAppendingPathComponent(fileName)
    UIGraphicsBeginPDFContextToFile(pdfPath, CGRectZero, nil)
    UIGraphicsBeginPDFPageWithInfo(rect, nil)
    var currentContext:CGContextRef = UIGraphicsGetCurrentContext()
    imageView.image?.drawInRect(rect)
    UIGraphicsEndPDFContext()
}

0 个答案:

没有答案