3

我有这个代码来做 AirPrint 文本视图文本

-(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];
}

但我没有像 iPad 中的默认 pinter 选项那样弹出任何打印机选项弹出窗口。我没有使用条形按钮,我有一个 UIbutton。如何正确执行此操作,我的代码有什么错误吗?._txtmainnote 是我的文本视图.

提前致谢。

4

3 回答 3

3

由此,:_printingItem

该对象必须是NSURLNSDataUIImageALAsset类的实例。

所以可能你必须通过类似的东西:

NSData* data=[_txtmainnote.text dataUsingEncoding:NSUTF8StringEncoding];
print.printingItem = data;
于 2012-05-16T10:48:03.603 回答
0

我得到了解决方案,只需将这行代码更改 [print presentAnimated:YES completionHandler:completionHandler];[print presentFromRect:CGRectMake(600, 650, 100, 200) inView:mainnotepageview animated:YES completionHandler:completionHandler]; 因为我正在使用 iPad 应用程序。

于 2012-05-16T10:44:21.363 回答
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];

}
于 2015-08-07T06:25:52.137 回答