3

I want to print a pdf file (iOS 8.1, AirPrint, Swift) directly to the printer. Printing is fine, but I get this message in Xcode:

2014-11-04 12:34:50.069 PrintApp[801:266564] -[PKPaperList matchedPaper:preferBorderless:withDuplexMode:didMatch:] paperToMatch= result= matchType=0

What does this mean?

This is my code:

let url: NSURL = NSURL(string:"http://www.sirup-shop.de/csv/test-paketlabel.pdf")!

let printInfo = UIPrintInfo(dictionary: nil)
printInfo.jobName = "Label"

let printController = UIPrintInteractionController.sharedPrintController()!
printController.printingItem = url
printController.printInfo = printInfo
printController.delegate = self
printController.printToPrinter(self.printer!, completionHandler: {
    (controller:UIPrintInteractionController!, completed:Bool, error:NSError!) -> Void in
    println("Label finished.")
})

Thanks a lot for you help.

Michael
  • 51
  • 1
  • 8
  • you may need to take a look on that answer: http://stackoverflow.com/a/24966715/1214122 – holex Nov 04 '14 at 12:03
  • @holex: yes, I saw this answer. The problem there was that he had a printFormatter _and_ a printingItem. The problem was solved by providing only the printFormatter. But I have only the printingItem. – Michael Nov 04 '14 at 12:20
  • @Michael Hi, we are trying to print pdf directly in flutter, will this allow in iOS? would apple reject build due to security issue? – Ruchira More Feb 16 '21 at 12:49
  • @RuchiraMore, I am sorry, I don't know anything about Flutter. – Michael Feb 16 '21 at 18:23

2 Answers2

5

This is the Swift version based on @Alok's answer

let printController = UIPrintInteractionController.shared
    let printInfo = UIPrintInfo(dictionary: [:])
    printInfo.outputType = UIPrintInfoOutputType.general
    printInfo.orientation = UIPrintInfoOrientation.portrait
    printInfo.jobName = "Sample"
    printController.printInfo = printInfo
    printController.showsPageRange = true
    printController.printingItem = NSData(contentsOf: URL(string: "https://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611_sample_explain.pdf")!)

    printController.present(animated: true) { (controller, completed, error) in
        if(!completed && error != nil){
            NSLog("Print failed - %@", error!.localizedDescription)
        }
        else if(completed) {
            NSLog("Print succeeded")
        }
    }
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Vitor Navarro
  • 171
  • 3
  • 6
2

I am sharing Objective-C Code, You can take this as a reference.

UIPrintInteractionController *pc = [UIPrintInteractionController
                                    sharedPrintController];
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.orientation = UIPrintInfoOrientationPortrait;
printInfo.jobName =@"Report";

pc.printInfo = printInfo;
pc.showsPageRange = YES;
pc.printingItem = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://test.com/Print_for_Client_Name.pdf"]];


UIPrintInteractionCompletionHandler completionHandler =
^(UIPrintInteractionController *printController, BOOL completed,
  NSError *error) {
    if(!completed && error){
        NSLog(@"Print failed - domain: %@ error code %ld", error.domain,
              (long)error.code);
    }
};


[pc presentFromRect:CGRectMake(0, 0, 300, 300) inView:self.view animated:YES completionHandler:completionHandler];
Alok
  • 24,880
  • 6
  • 40
  • 67