Got it working. I wrapped my SwiftUI View to be printed(and displayed) in a local function like this:
private func generateView() -> some View {
VStack { .... }
}
Then I created a func to save the some View as a PDF in the document directory using ImageRenderer. The func also returns the PDF's URL which was created using URL.documentsDirectory.appending(path:)
Then I created another func using UIPrintInteractionController and the PDF's URL to present the print controller for the saved pdf.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: