【问题标题】:UIPrintInteractionController Printingitems - DismissesUIPrintInteractionController Printingitems - 关闭
【发布时间】:2015-05-15 23:26:21
【问题描述】:

我已使用此功能成功打印了一份 PDF:

-(void)printPDF{

    NSString* fileName = @"Certificate.PDF";

    NSArray *arrayPaths =
    NSSearchPathForDirectoriesInDomains(
                                        NSDocumentDirectory,
                                        NSUserDomainMask,
                                        YES);
    NSString *path = [arrayPaths objectAtIndex:0];
    NSString* pdfFileName = [path stringByAppendingPathComponent:fileName];


    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
    ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
        if (!completed && error) NSLog(@"Print error: %@", error);
    };

    NSData *pdfData = [[NSFileManager defaultManager] contentsAtPath:pdfFileName];

    printController.printingItem = pdfData;

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        [printController presentFromRect:self.btnPrint.frame inView:self.btnPrint.superview
                                animated:YES completionHandler:completionHandler];
    } else {
        [printController presentAnimated:YES completionHandler:completionHandler];
    }

}

当我想打印几个 PDF 时,我已将其放入一个数组(证书)中。在我选择打印机之前,printController 对话框关闭,并且出现以下错误。 “警告:在演示或关闭过程中尝试从视图控制器中关闭!”

我是否需要为 printcontroller 使用一些 delgate 方法,或者有什么问题?

这是我打印几个 PDF 文档的尝试。

-(void)printAllPDF{

    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
    ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
        if (!completed && error) NSLog(@"Print error: %@", error);

    };

    printController.printingItems = certificates;

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        [printController presentFromRect:self.btnPrintAll.frame inView:self.btnPrintAll.superview
                                animated:YES completionHandler:completionHandler];

    } else {
        [printController presentAnimated:YES completionHandler:completionHandler];
    }
}

【问题讨论】:

    标签: ios objective-c pdf uiprintinteractioncntrler


    【解决方案1】:

    我的错……我应该多花点时间调试一下。

    我实际上是在我的“数组循环”中调用 PrintPDF... Ups...对不起:-(

    - (IBAction)fcPrintAllBtn:(UIButton *)sender {
    
        [certificates removeAllObjects];
    
        for (Paxtype *pax in paxArray) {
            [self createPDFWithPax:pax Balloon:self.edtFlightBalloon.text Landing:self.edtLandingSite.text Date:self.edtFlightDate.text Gender:pax.sBookGender PaxTitle:self.edtPaxTitle.text Start:self.edtLaunchSite.text Speed:self.edtMaxSpeed.text Altitude:self.edtMaxAlt.text
                          Distance:self.edtDistance.text];
            NSString* fileName = @"Certificate.PDF";
    
            NSArray *arrayPaths =
            NSSearchPathForDirectoriesInDomains(
                                                NSDocumentDirectory,
                                                NSUserDomainMask,
                                                YES);
            NSString *path = [arrayPaths objectAtIndex:0];
            NSString* pdfFileName = [path stringByAppendingPathComponent:fileName];
            NSData *pdfData = [[NSFileManager defaultManager] contentsAtPath:pdfFileName];
    
            [certificates addObject:pdfData];
    
            [self printAllPDF];   <-----This should not be here !!!
    
        }
    
        [self printAllPDF];   <-----But here !!
    
        NSLog(@"Certificates %i", certificates.count); 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-13
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多