Found the solution to my problem.
In my code above, I had a pdfDocument object and then I created the PDFView and tried to send it to the printer using NSPrintOperation.
I think setting the PDFView document as the downloaded pdf was the issue. So What I came up with was using the PDFDocument.printOperation and changed my printDocumentFunction
private func printPDFDocumentt(_ document: PDFDocument) {
let printInfo = NSPrintInfo.shared
printInfo.horizontalPagination = .fit
printInfo.verticalPagination = .fit
printInfo.orientation = .portrait
printInfo.topMargin = 0
printInfo.bottomMargin = 0
printInfo.leftMargin = 0
printInfo.rightMargin = 0
printInfo.isHorizontallyCentered = true
printInfo.isVerticallyCentered = true
let scale: PDFPrintScalingMode = .pageScaleDownToFit
let printOp = document.printOperation(for: printInfo, scalingMode: scale, autoRotate: true)
DispatchQueue.main.async {
printOp?.run()
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: