Cocoa 能否依靠NSAutoPagination将NSView清晰地划分为多个页面?
我正在编写一个基于文档的cocoa应用程序,允许用户打印多页文档。我试图利用cocoa的能力将一个非常高的NSView拆分为一列大小相同的页面:Cocoa 能否依靠NSAutoPagination将NSView清晰地划分为多个页面?,cocoa,printing,document,Cocoa,Printing,Document,我正在编写一个基于文档的cocoa应用程序,允许用户打印多页文档。我试图利用cocoa的能力将一个非常高的NSView拆分为一列大小相同的页面: - (void)printDocumentWithSettings:(NSDictionary *)printSettings showPrintPanel:(BOOL)showPrintPanel delegate:(id)delegate
- (void)printDocumentWithSettings:(NSDictionary *)printSettings
showPrintPanel:(BOOL)showPrintPanel
delegate:(id)delegate
didPrintSelector:(SEL)didPrintSelector
contextInfo:(void *)contextInfo
{
[self.printInfo setVerticallyCentered:0];
[self.printInfo setHorizontallyCentered:0];
[self.printInfo setHorizontalPagination:NSFitPagination];
[self.printInfo setVerticalPagination:NSAutoPagination];
[self.printInfo setRightMargin:0];
[self.printInfo setLeftMargin:0];
[self.printInfo setTopMargin:0];
[self.printInfo setBottomMargin:0];
NSPrintOperation *printOperation =
[NSPrintOperation printOperationWithView:self.printView];
[printOperation runOperationModalForWindow:[self.printView window]
delegate:nil
didRunSelector:nil
contextInfo:nil];
}
正在讨论的视图(self.printView)的宽度正好是self.printInfo.paperSize的宽度,高度正好是self.printInfo.paperSize的倍数。鉴于我已将所有printInfo页边距设置为零,当我调用此函数时:
[self.printInfo setVerticalPagination:NSAutoPagination];
我希望这些页面被完美地分割成一列,在它们的边界上均匀地分开。但是,当我打印文档时,分页会稍微垂直偏移
这样做的效果是,第一页的底部边距似乎有少量的额外空间。第二个页面在页面上的显示比它应该的稍低,第三个页面甚至更低,依此类推,直到它在第六页左右完全失控,看起来与原始的printView完全不同
尽管我已经验证了我的printView在单独的实验中使用setVerticallyCentered:1和setHorizontallyCentered:1整体查看时看起来非常好
我知道苹果公司的另一种(更复杂的)分页方法,包括子类化NSView并覆盖knowsPageRange:和rectForPage:,但我更愿意避免这种情况,除非我使用的技术存在已知问题,使其不可靠