2

I have spent some hours reading Google and Stack Overflow on this, the result is an increase in bafflement!

I would have thought what I am trying to do would be easy.

I have a view that includes a background image and overlayed text (its a certificate) that needs to be printed. I have the view displayed, now need to print.

I have tried following macOS Printing in Swift and to get the window How to access own window within SwiftUI view?

The app is OSX desktop Swift and Xcode etc all latest versions.

I would post sample code but I am at a loss as at what wat to do it. Do I need the host window? Do I need to create a view just for the print? Do I need NSPrintOperation?

Many thanks.

Ian
  • 412
  • 1
  • 4
  • 18
  • I have got partway there, actually getting something out on the printer! Text not quite aligned as I would like but I think I know how to solve that. The big issue now is that the background image is not printed. Code I am using is as follows: @IBAction func print2(_ sender : Any){ let printingView = self.window.contentView let printOperation = NSPrintOperation(view: printingView!, printInfo: NSPrintInfo()) printOperation.showsPrintPanel = true printOperation.showsProgressPanel = true printOperation.run() } Any ideas? – Ian Jun 24 '20 at 11:19

0 Answers0