Print is not working on ipad.

Discussion in 'iPad' started by manoj, Dec 27, 2010.

  1. manoj macrumors newbie

    Joined:
    Nov 22, 2007
    #1
    my application though paper feed action is called but nothing is printed and paper comes out blank..
    I am use the following code for print.

    Code:
     -(IBAction)printButtonAction:(id)sender{
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
     NSString *documentsDirectory = [paths objectAtIndex:0];
    
     NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"Preview.pdf"];
    
     NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:writableDBPath]];
    
     UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
     UIPrintInfo *printInfo = [UIPrintInfo printInfo];
     printInfo.outputType = UIPrintInfoOutputGeneral;
     printInfo.jobName = [writableDBPath lastPathComponent];
     printInfo.duplex = UIPrintInfoDuplexLongEdge;
     controller.printInfo = printInfo;
     controller.showsPageRange = YES;
     controller.printingItem = data;
    
     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);
     };
    
    
     UIViewPrintFormatter *viewFormatter = [documentView viewPrintFormatter];
        viewFormatter.startPage = 0;
        controller.printFormatter = viewFormatter;
    
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
      [controller presentFromBarButtonItem:printButton animated:YES
             completionHandler:completionHandler];
     } else {
      [controller presentAnimated:YES completionHandler:completionHandler];
     }
    
    
    
    }
    Thanks
    Manoj
     
  2. saberahul macrumors 68040

    Joined:
    Nov 6, 2008
    Location:
    USA
    #2
    There is a programming section. You should post there.
     

Share This Page