AirPrint UIImage A4

591 Views Asked by At

My app is currently creating an image at a size of 2480 3508 (A4 Page) How do I send this image to AirPrint on an A4 page? Once the image is created it saves it to the photos app and I would also like to send it to print. Any ideas? Thanks

2

There are 2 best solutions below

0
On

You will need to use a UIPrintInteractionController, and set the image as printingItem. Depending on the print quality you choose (photo mode or standard) the default paper may be smaller than a4, but the user can select a4 in the print dialog.

`- (void) printImage: (UIImage *) myImage {
UIPrintInteractionController *controller = [UIPrintInteractionController  sharedPrintController];
    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputPhoto;
    printInfo.jobName = @"Testprint";
    printInfo.duplex = UIPrintInfoDuplexNone;
    controller.printingItem = myImage;
    controller.showsPaperSelectionForLoadedPapers = YES;

   void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
    ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
    if (!completed && error)
        NSLog(@"FAILED! due to error in domain %@ with error code %u",
              error.domain, error.code);
       NSLog(@"Completed: %s", (completed?"YES":"NO"));
    };
  [controller presentAnimated:YES completionHandler:completionHandler];
}`
0
On

SWIFT 3 VERSION

func printNow(_ image: UIImage){
    let controller = UIPrintInteractionController.shared
        let printInfo = UIPrintInfo.printInfo()
        printInfo.outputType = .photoGrayscale//.photo
        printInfo.jobName = "Testprint";
        printInfo.duplex = .none
        controller.printingItem = image
        controller.showsPaperSelectionForLoadedPapers = false

        controller.present(animated: true) { (controller, completed, error) in
            if (!completed && (error != nil)) {
                print("FAILED! due to error \(error.debugDescription)")
            }
            print("Completed: \(completed)")
    }
}