Print PDF file on iphone or ipad

后端 未结 4 1454
北海茫月
北海茫月 2021-02-20 14:47

I attached a file to the mail I am using this code.

[mail addAttachmentData:[myView PDFData] mimeType:@\"application/pdf\" fileName:@\"name.pdf\"];
4条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-20 15:06

    write below code and check it

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *pathFolder = [NSString stringWithFormat:@"%@",pdfFileName];
    NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:pathFolder];
    NSURL *targetURL = [NSURL fileURLWithPath:path];
    
    UIPrintInteractionController *pc = [UIPrintInteractionController sharedPrintController];
    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;
    printInfo.orientation = UIPrintInfoOrientationPortrait;
    printInfo.jobName =@“Print”;
    printInfo.duplex = UIPrintInfoDuplexLongEdge;
    
    pc.printInfo = printInfo;
    pc.showsPageRange = YES;
    pc.printingItem = targetURL;
    
    UIPrintInteractionCompletionHandler completionHandler =
        ^(UIPrintInteractionController *printController, BOOL completed,
          NSError *error) {
         if(!completed && error){
             NSLog(@"Print failed - domain: %@ error code %ld", error.domain, (long)error.code);
         }
    };
    [pc presentFromRect:shareButton.frame inView:self.view animated:YES completionHandler:completionHandler];
    

提交回复
热议问题