how do I print the contents of the PdfView?

XCode - Swift

private var mPdfView = PDFView()

private var mDocumentData: Data?

mDocumentData = MakePdfDocument()

mPdfView.document = PDFDocument(data: mDocumentData!)

let printInfo = UIPrintInfo(dictionary: nil)

printInfo.outputType = UIPrintInfo.OutputType.general

printInfo.jobName = “JobName”

let printController = UIPrintInteractionController.shared

printController.printInfo = printInfo

printController.printingItem = mPdfView

printController.showsNumberOfCopies = true

printController.present(animated: true, completionHandler: nil)

**When print is executed, only the blank screen is output, not the generated PDF.

How can I print the generated PDF content?**

Try this

if let pdfData = pdfView.document?.dataRepresentation() {
   let printInfo = UIPrintInfo(dictionary: nil)
   printInfo.jobName = "page"
   printInfo.outputType = .general

   let printController = UIPrintInteractionController.shared
   printController.printInfo = printInfo
   printController.showsNumberOfCopies = true
   printController.printingItem = pdfData
   printController.present(animated: true, completionHandler: nil)
}

I hope this helps.

this is really helpful thank you!

i used this for testing that i can open the print preview within my app:

import PDFKit

class PDFManager {
    
    func printTest() -> Error? {
        let pdfView = PDFView()
        pdfView.document = PDFDocument()
        
        guard let dataRepresention = pdfView.document?.dataRepresentation() else {
            print("dataRepresention is nil")
            return URLError(.badURL)
        }
        
        let printInfo = UIPrintInfo(dictionary: nil)
        printInfo.jobName = "Class Plan"
        printInfo.outputType = .general
        
        let printController = UIPrintInteractionController.shared
        printController.printInfo = printInfo
        printController.showsNumberOfCopies = true
        printController.printingItem = dataRepresention
        printController.present(animated: true, completionHandler: nil)
        
        return nil
    }
    
}
how do I print the contents of the PdfView?
 
 
Q