1

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

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

当内容/图形多于一页时,我有以下代码打印 2 个 pdf,但我想要 1 个 2 页的 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];
}
4

0 回答 0