2010-12-28 7 views
1

내 용지 공급 동작이 호출되었지만 아무것도 인쇄되지 않고 용지가 비어 있습니다. 인쇄를 위해 다음 코드를 사용하고 있습니다.인쇄가 ipad에서 작동하지 않습니다

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



} 

감사

피카의 자이나교 나는 아래의 코드가 작동 것이라고 생각

답변

0

,

-(IBAction)printButtonAction:(id)sender{ 
    float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue]; 

if (systemVersion>4.1) { 

    NSData *myPdfData = [NSData dataWithContentsOfFile:pdfPath]; //check the value inside |myPdfData| and |pdfPath| is the path of your pdf. 
    UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController]; 
    if (controller && [UIPrintInteractionController canPrintData:myPdfData]){ 
     controller.delegate = delegate; //if necessary else nil 
     UIPrintInfo *printInfo = [UIPrintInfo printInfo]; 
     printInfo.outputType = UIPrintInfoOutputGeneral; 
     printInfo.jobName = [pdfPath lastPathComponent];  
     //printInfo.duplex = UIPrintInfoDuplexLongEdge; 
     controller.printInfo = printInfo; 
     controller.showsPageRange = YES; 
     controller.printingItem = myPdfData;  

     // We need a completion handler block for printing. 
     UIPrintInteractionCompletionHandler completionHandler = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) { 
      if(completed && error){ 
       NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code); 
      } 
     }; 

     [controller presentFromRect:rect inView:senderView animated:YES completionHandler:completionHandler]; 
    }else { 
     NSLog(@"Couldn't get shared UIPrintInteractionController!"); 
    } 
} 

난 당신이 놓친 생각, 당신이 가져온 PDF 파일의 경로를 확인 '/' Documents 디렉토리 다음에. 중단 점을 넣고 경로를 확인한 다음 | 데이터 | 지정한 경로의 콘텐츠에 대한 변수입니다. 그것을 시도하고 통해 ur 의견으로 응답하십시오. :)

관련 문제