gpt4 book ai didi

ios - 无法找到在 Swift XCode 中创建的 Pdf 文件

转载 作者:行者123 更新时间:2023-11-29 01:09:09 25 4
gpt4 key购买 nike

Iv 使用 Tom 提供的以下代码创建了一个 Pdf 文件,并且

PDF Generation Swift

我在查找我使用 Tom 的代码创建的文档时遇到了同样的问题。我搜索我的 Mac HD,仍然没有文档,程序也没有崩溃。当我查看日志时,它显示它已存储在以下路径

pdfPathWithFileName 字符串“/Users/cleota/Library/Developer/CoreSimulator/Devices/B72A97D0-339E-4E79-AED6-4991D3B7C4B7/data/Containers/Data/Application/7A7789C4-27C5-45FB-8604-E36865609764/Documents/艾兹作文测试.pdf"

但是当我去那里时,这些文件夹(Library/Developer/CoreSimulator/Devices)并不在它所说的存储位置。请问有什么想法吗?

    @IBAction func createPdfDocument(sender: AnyObject) {

let fileName: String = "Taumaoe.pdf"
let path:NSArray = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let documentDirectory: AnyObject = path.objectAtIndex(0)
let pdfPathWithFileName = documentDirectory.stringByAppendingPathComponent(fileName as String)

print(pdfPathWithFileName)

generatePdf(pdfPathWithFileName)

}

func generatePdf(filepath: String){

UIGraphicsBeginPDFContextToFile(filepath, CGRectZero, nil)
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 850, 1100), nil)
drawBackground()

}

func drawBackground(){

var context:CGContextRef = UIGraphicsGetCurrentContext()!

// var rect:CGRect = CGRectMake(0, 0, CGSize.height, CGSize.width)
//CGContextSetFillColorWithColor(context, UIColor.greenColor().CGColor)
//CGContextFillRect(context, rect)

var testView = UIView (frame: CGRectMake(0,0,850,1100))
testView.backgroundColor = UIColor.yellowColor()

var label = UILabel (frame: CGRectMake(10,10,100,20))
label.textColor = UIColor.redColor()
label.backgroundColor = UIColor.lightGrayColor()
label.text = "I'am a test label"
testView.addSubview(label)

testView.layer.renderInContext(context)

UIGraphicsEndPDFContext()

//Title of 1st option of MainController

let sexyKeyWordscontroller = UIAlertController(title: "Ezy Essay Saved!", message: "Well done! Your Ezy Essay Pdf document has been saved at the following path: ", preferredStyle: UIAlertControllerStyle.Alert)

let closeButton : UIAlertAction = UIAlertAction(title: "Close",
style: UIAlertActionStyle.Cancel,
handler: {
(alert: UIAlertAction!) in sexyKeyWordscontroller.dismissViewControllerAnimated(true,
completion: nil)
})


sexyKeyWordscontroller.addAction(closeButton)

self.presentViewController(sexyKeyWordscontroller, animated: true, completion: nil)


}

谢谢

最佳答案

如果您在按钮事件中打印出 pdfPathWithFileName,您将获得文件路径。找到文件路径后,打开查找器窗口并在文件菜单中单击:前往> 前往文件夹

您打印出的路径将如下所示:

/Users/USERNAME/Library/Developer/CoreSimulator/Devices/...

将此复制到路径中的 Go to 文件夹中

~/Library/Developer/CoreSimulator/Devices/...

如果您只想打开文件夹的位置而不是文件本身,当然可以跳过路径中的最后一个“/xp.pdf”。

关于ios - 无法找到在 Swift XCode 中创建的 Pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35979491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com