0

i have a ViewController_A with a button_A. this button shows me the ViewController_B. this second view controller has content and a button_B.

i you press the button_b the following code will create a pdf file of the ViewController_B content:

let pdfData = contentVC_B.dataWithPDF(inside: contentVC_B.frame)
let fileURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false).appendingPathComponent("test.pdf")

do {
   try pdfData.write(to: fileURL, options: .atomic)
} catch {
   print(error)
}

This works fine. But now my question:

i would like to create a pdf file of the ViewController_B content with button_A (from the ViewController_A) without showing the ViewController_B.

is is possible? if yes, how can i realize it?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • So if I understand this correctly you want to pass `VC_B` to `VC_A` using a button on A? You should then be able to create the file with the content. I've never tried this so, I'm not sure it'll work. Look at this answer for help with passing data between VC's. Which I believe is really what you're asking here. https://stackoverflow.com/a/31934786/6448167 – KSigWyatt Jul 13 '17 at 13:41
  • Perhaps this then? https://stackoverflow.com/a/26229535/6448167 – KSigWyatt Jul 14 '17 at 17:22

1 Answers1

-1

Get ViewController_B, get contentVC_B and get the pdf data.

let storyBoard = NSStoryboard(name:"Main", bundle:nil)
let viewController_B = storyBoard.instantiateController(withIdentifier:"viewController_B") as! NSViewController
let contentVC_B = viewController_B.view
let pdfData = contentVC_B.dataWithPDF(inside: contentVC_B.frame)
Willeke
  • 14,578
  • 4
  • 19
  • 47