Creating a PDF in Swift

时间:2015-10-30 22:11:44

标签: swift macos cocoa pdf swift2

I want to be able to be able to create a PDF of my view controller. Essentially, I need a screenshot of the view controller to be exported as a PDF. Apple don't seem to have any documentation on this (for OS X development) in Swift, anyone got any ideas?

Thanks

Just in case anyone was wondering.. The solution to this problem is as follows (apologies for not posting sooner - I assumed as this was a 'duplicate' question then the answer would lie elsewhere..

//  Define the bounds of the view
    let rect: NSRect = self.view.bounds

//  Create a PDF version and save it to the desktop
    self.view.dataWithPDFInsideRect(rect).writeToFile("/Users/Jay/Desktop/test.pdf", atomically: false)

//  Automatically open this newly generated file
    NSWorkspace.sharedWorkspace().openFile("/Users/Jay/Desktop/test.pdf")

0 个答案:

没有答案
相关问题