Printing UIImage Using AirPrint Disables Content

I am UIImage using AirPrint, but the fields are not correct. Here's what it looks like when it prints:
Photo of printout

Is there a way so that I can fit perfectly on paper?

Here is the code on request:

  UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController]; //pic.delegate = del; UIPrintInfo *printInfo = [UIPrintInfo printInfo]; printInfo.outputType = UIPrintInfoOutputGeneral; printInfo.jobName = [NSString stringWithFormat:@"New Ticket"]; pic.printInfo = printInfo; pic.printingItem = [UIImage imageWithContentsOfFile:path]; void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) { if (!completed && error) { UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error." message:[NSString stringWithFormat:@"An error occured while printing: %@", error] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [av show]; [av release]; } }; [pic presentAnimated:YES completionHandler:completionHandler]; 
+6
source share
1 answer

Your best bet is probably to scale the image to the ratio of the printed image, so you can see it all on the page.

There are several ways to do this, so I’ll just tell you how to do it. I support a class called ANImageBitmapRep , which has several different types of image scaling. The type of zoom you want preserves the whole image, but centers it inside a rectangle of a certain size. First, you must add the ANImageBitmapRep source files to your project, and #import ANImageBitmapRep.h:

 #import "ANImageBitmapRep.h" 

Then scale the image as follows:

 pic.printingItem = [[UIImage imageWithContentsOfFile:path] imageFittingFrame:CGSizeMake(478, 640)]; 

You can change CGSizeMake(x, y) to whatever you want to adjust the scale and resolution of the scaled image.

0
source

Source: https://habr.com/ru/post/898611/


All Articles