我使用UIMarkupTextPrintFormatter
从我的应用打印一些HTML。如果我让打印格式化程序打印到整个页面,它会很好用。如何从UIPrintFormatter获得精确的pageCount
但我想限制在页面的一半格式打印 - 而实现这一点我设置contentInsets
属性一旦我知道纸张的尺寸(我设置contentInsets当UIPrintInteractinControllerDelegate
方法- (UIPrintPaper *)printInteractionController: (UIPrintInteractionController *)pic choosePaper:(NSArray *)paperList
被调用。)
这也适用 - 打印正确地限制到使用contentInsets定义的页面区域。
但是打印页数是错误的。我得到的页数好像打印作业一直使用默认的contentInsets(0,0,0,0)。
我怎样才能打印正确的页数?为什么UIMarkupTextPrintFormatter
上的pageCount
属性总是返回0?
这里的打印作业设置代码:
UIPrintInteractionController* pic = [UIPrintInteractionController sharedPrintController];
pic.delegate = self;
UIPrintInfo* pi = [UIPrintInfo printInfo];
pi.orientation = UIPrintInfoOrientationLandscape;
pi.outputType = UIPrintInfoOutputGrayscale;
pi.duplex = UIPrintInfoDuplexNone;
pic.printInfo = pi;
UIMarkupTextPrintFormatter* mtpf = [[UIMarkupTextPrintFormatter alloc] initWithMarkupText: myHTML ];
pic.printFormatter = mtpf;
[pic presentAnimated: YES completionHandler:^(UIPrintInteractionController *printInteractionController, BOOL completed, NSError *error)
{
}];
,并委托方法:
- (UIPrintPaper *)printInteractionController: (UIPrintInteractionController *)pic choosePaper:(NSArray *)paperList
{
// we want letter paper
UIPrintPaper* printPaper = [UIPrintPaper bestPaperForPageSize: CGSizeMake(612 , 792) withPapersFromArray: paperList];
UIMarkupTextPrintFormatter* mtpf = (UIMarkupTextPrintFormatter*)pic.printFormatter;
CGFloat padding = (printPaper.paperSize.height - printPaper.printableRect.size.height)/2.0;
mtpf.contentInsets = UIEdgeInsetsMake(0, 0, 0, (printPaper.printableRect.size.height/2.0) + padding);
// always 0 ???
NSLog(@"pageCount: %d", mtpf.pageCount);
return printPaper;
}