I am attempting to print a view from swiftui to a printer. Everything seems to work fine except when the print dialog appears the preview is an empty view. My PrintView has a large black box with text in it just for testing but will not appear in print preview.
func fPrint() {
let printingView = UIHostingController(rootView: PrintView()).view
// GET VIEW AS NSDATA FOR PDF
let pdfData:NSMutableData = NSMutableData()
let pageSize:CGRect = CGRect()
UIGraphicsBeginPDFContextToData(pdfData, pageSize, nil)
let pdfContext:CGContext = UIGraphicsGetCurrentContext()!
// CREATE A SINGLE PAGE PDF
UIGraphicsBeginPDFPage()
printingView?.layer.render(in: pdfContext)
UIGraphicsEndPDFContext();
// SETUP PRINT INFO
let printInfo = UIPrintInfo(dictionary:nil)
printInfo.outputType = UIPrintInfo.OutputType.general
printInfo.jobName = "Print Job"
printInfo.orientation = .portrait
// SETUP PRINT CONTROLLER
let printController = UIPrintInteractionController.shared
printController.printInfo = printInfo
printController.showsNumberOfCopies = true
printController.showsPaperSelectionForLoadedPapers = true
printController.printingItem = pdfData
printController.present(animated: true, completionHandler: nil)
}