Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the Job Status of UIPrintInteractionController in Swift

I have a problem: I want to know the status of the print job. I'm printing out a PDF file which is temporarily stored in a cloud drive. I want to delete that file after the print job is done. How can I realize this in swift? Here is a snippet of my code:

 // 1
    let printController = UIPrintInteractionController.sharedPrintController()
    // 2
    let printInfo = UIPrintInfo(dictionary:nil)
    printInfo.outputType = UIPrintInfoOutputType.General
    printController.showsNumberOfCopies = false
    printController.showsPageRange = false
    printInfo.jobName = "PDF ID: " + pdfObjectID
    printController.printInfo = printInfo

    // 3
    //let formatter = UIMarkupTextPrintFormatter(markupText: "Test")
    let formatter = pdf.viewPrintFormatter()
    formatter.contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
    printController.printFormatter = formatter

    // show PrintController
    printController.presentAnimated(true, completionHandler: nil)

Do you have any suggestions? Thanks :)

like image 313
CortexA8 Avatar asked Nov 16 '25 08:11

CortexA8


1 Answers

I haven't tested it myself, but according to the documentation, you can pass a UIPrintInteractionCompletionHandler as completionHandler: parameter:

When a print job concludes, you can reset any state set up for printing and do related housekeeping tasks.

A simple example:

    printController.presentAnimated(true) { (controller, success, error) -> Void in
        if success {
            // Printed successfully
            // Remove file here ...
        } else {
            // Printing failed, report error ...
        }
    }
like image 75
Martin R Avatar answered Nov 19 '25 09:11

Martin R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!