How to print AirPrint UITextField text

I have this code to make AirPrint text text

-(IBAction)_clickbtnprintermainnote:(id)sender
{
    UIPrintInteractionController *print = [UIPrintInteractionController sharedPrintController];

    print.delegate = self;
    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;
    printInfo.jobName =@"Nots of MyBibleApp";
    printInfo.duplex = UIPrintInfoDuplexLongEdge;
    print.printInfo = printInfo;
    print.showsPageRange = YES;
    print.printingItem = _txtmainnote.text;

    void (^completionHandler)(UIPrintInteractionController *,BOOL, NSError *) = ^(UIPrintInteractionController *print,BOOL completed, NSError *error) {
        if (!completed && error) {
            NSLog(@"houston we have a problem");
        }
    };
    [print presentAnimated:YES completionHandler:completionHandler];
}

but I didn’t have a pop-up for the printer parameter, for example, the default pinter parameter in iPad.am, without using the panel button, I have UIbutton.how to do it right, is there any error in my code ?. _ txtmainnote is my text.

Thanks in advance.

+3
source share
3 answers

From the this , printingItem:

The object must be an instance of NSURL, NSData, UIImageor ALAsset.

maybe you need to pass something like:

NSData* data=[_txtmainnote.text dataUsingEncoding:NSUTF8StringEncoding];
print.printingItem = data;
+3
source

, [print presentAnimated:YES completionHandler:completionHandler]; [print presentFromRect:CGRectMake(600, 650, 100, 200) inView:mainnotepageview animated:YES completionHandler:completionHandler]; iPad.

0
@interface ViewController ()
@property (strong, nonatomic) IBOutlet UILabel *label;
@property (strong, nonatomic) IBOutlet UIView *mainnotepageview;
@property (strong, nonatomic) IBOutlet UITextField *text02;
@property (strong, nonatomic) IBOutlet UITextView *myTextView;

 - (IBAction)btnSettingsTapped:(id)sender
{
 NSMutableString *printBody = [NSMutableString stringWithFormat:@"%@,  %@",self.myTextView.text, self.label.text];
//[printBody appendFormat:@"\n\n\n\nPrinted From *myapp*"];

UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.delegate = self;

UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = self.label.text;
pic.printInfo = printInfo;

UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc] initWithText:printBody];
textFormatter.startPage = 0;
textFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0); // 1 inch margins
textFormatter.maximumContentWidth = 6 * 72.0;
pic.printFormatter = textFormatter;

pic.showsPageRange = YES;

void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
    if (!completed && error) {
        NSLog(@"Printing could not complete because of error: %@", error);
    }
};

//[pic presentFromBarButtonItem:self.rightButton animated:YES completionHandler:completionHandler];
[pic presentFromRect:CGRectMake(600, 650, 100, 200) inView:_mainnotepageview animated:YES completionHandler:completionHandler];

}
0
source

All Articles