I found a couple items regarding AirPrint. I want to print a frame in a view i have but am having some trouble.
struct ContentView: View {
var body: some View {
VStack {
Group{
Image(systemName: "person.fill")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
}
}
.frame(width: 390, height: 300, alignment: .center)
.border(Color.black)
.cornerRadius(15.0)
.padding()
Button{
print()
} label:
{
Text("print")
}
}
private func print(){
// UIPrintInteractionController presents a user interface and manages the printing
let printController = UIPrintInteractionController.shared
// UIPrintInfo contains information about the print job
let printInfo = UIPrintInfo(dictionary: nil)
printInfo.outputType = UIPrintInfo.OutputType.general
printInfo.jobName = "myPrintJob"
printController.printInfo = printInfo
// You can also format printing text, for example, the insets for the printing page
let formatter = UIMarkupTextPrintFormatter(markupText: "TestDevLab blog 2018")
formatter.perPageContentInsets = UIEdgeInsets(top: 90, left: 90, bottom: 90, right: 90)
printController.printFormatter = formatter
// Present print controller like usual view controller. Also completionHandler is available if needed.
printController.present(animated: true, completionHandler: nil)
}
}
the func "print" was pulled from an article i found and prints the text: "TestDevLab blog"
i also found an article to print a view as a image but am having trouble implementing it into the above.
UIGraphicsBeginImageContextWithOptions( view.frame.size, false, 0)
view.drawHierarchy(in: view.bounds, afterScreenUpdates: false)
let viewImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
let information = UIPrintInfo(dictionary: nil)
information.outputType = UIPrintInfo.OutputType.general
information.jobName = "Print Badge"
let printerViewController = UIPrintInteractionController.shared
printerViewController.printInfo = information
printerViewController.printingItem = viewImage
printerViewController.present(animated: true, completionHandler: nil)
The UIGraphicsBeginImageContextWithOptions ( view.frame.size, false, 0). how do i set the view to my ContentView()?
anyone done anything like this before??
thanks.
ja