打印多个iOS页面和一个pdf

时间:2013-07-09 10:24:12

标签: ios printing

我有以下代码,当有比一页更多的内容/图形时打印2 pdf,但我想要2页的1 pdf。我需要改变什么?

它是在iOS 5及更高版本的Xcode中制作的。

我有以下代码,当有比一页更多的内容/图形时打印2 pdf,但我想要2页的1 pdf。我需要改变什么?

-(void) addPrintView {
    UIView* v = nil;
    if([printViews lastObject] != nil) {
        UIView* lastSubView = [printViews lastObject];
        v = [[UIView alloc] initWithFrame:CGRectMake(0, lastSubView.frame.origin.y + lastSubView.frame.size.height, 824, 1265)];
    } else {
        v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 824, 1265)];
    }
    [v setOpaque:YES];
    [v setBackgroundColor:[UIColor whiteColor]];

    [printViews addObject:v];
    [self.scrollView addSubview:v];
    [self.scrollView setContentSize:CGSizeMake(824, (1265*[printViews count])+220) ];
    //add pagenumber
    UILabel *lblPageNumber = [[UILabel alloc] initWithFrame:CGRectMake(824 - 30, 1265 - 50 , 30, 30)];
    lblPageNumber.text = [NSString stringWithFormat:@"%i", printViews.count];
    lblPageNumber.font = [UIFont systemFontOfSize:12];
    lblPageNumber.tag = 1000 + [printViews count];
    [lblPageNumber setHidden:YES];
    [_pageNumbers addObject:lblPageNumber];
}

- (IBAction)printContent:(id)sender {

    if(!self.orderOperationCenter.order.signature){
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Signature" message:@"Please provide a signature" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
        return;
    }

    dispatch_queue_t queue = dispatch_get_main_queue();
    dispatch_async(queue, ^{
        [self.btnFinish setHidden:YES];
        [self.btCancel setAlpha:0];
    });

    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];

    pic.delegate = self;

    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;
    printInfo.jobName = @"Versmissen";
    printInfo.duplex = UIPrintInfoDuplexNone;

    pic.printInfo = printInfo;
    pic.printFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0);
    pic.printFormatter.maximumContentWidth = 6 * 72.0;
    pic.printInfo.orientation = UIPrintInfoOrientationPortrait;
    pic.showsPageRange = YES;

    NSMutableArray* arr = [[NSMutableArray alloc] init];

    for(int i = 0; i < printViews.count; i++){
        UIView* v = [printViews objectAtIndex:i];
        [v addSubview:[_pageNumbers objectAtIndex:i]];
        [arr addObject:[UIImage imageWithView:v]];

    }

    [pic setPrintingItem:arr];

    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);
    };
    [pic presentFromBarButtonItem:self.printButton animated:YES completionHandler:completionHandler];

}
-(void)printInteractionControllerDidFinishJob:(UIPrintInteractionController *)printInteractionController {
    UIAlertView* view = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Succesfully printed the order overview." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
    [view show];
    [self.btnFinish setHidden:NO];
    for(UIView* v in _pageNumbers){
        [v removeFromSuperview];
    }
    [self.btCancel setAlpha:1];
}

-(UIPrintPaper *)printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray *)paperList {
    CGSize size = [[printViews lastObject] frame].size;
    return [UIPrintPaper bestPaperForPageSize:size withPapersFromArray:paperList];
}

0 个答案:

没有答案