Objective c Cocoa WebView获取用于打印的页码
我想做一件相当直截了当的事: 我有一个Web视图,其中包含我要打印的内容。我想添加一个包含页码的自定义页脚 我只是不知道如何获得视图的滚动位置 以下是我尝试过的:Objective c Cocoa WebView获取用于打印的页码,objective-c,macos,cocoa,printing,webview,Objective C,Macos,Cocoa,Printing,Webview,我想做一件相当直截了当的事: 我有一个Web视图,其中包含我要打印的内容。我想添加一个包含页码的自定义页脚 我只是不知道如何获得视图的滚动位置 以下是我尝试过的: NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo]; [printInfo setTopMargin:30]; [printInfo setBottomMargin:30]; [printInfo setLeftMargin:30]; [printInfo setRightMa
NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
[printInfo setTopMargin:30];
[printInfo setBottomMargin:30];
[printInfo setLeftMargin:30];
[printInfo setRightMargin:30];
[printInfo setHorizontallyCentered:YES];
[printInfo setVerticallyCentered:NO];
[printInfo setOrientation:NSPaperOrientationPortrait];
[printInfo setHorizontalPagination:NSFitPagination];
NSMutableDictionary* printSettings = printInfo.printSettings;
printSettings[NSPrintHeaderAndFooter] = @(YES);
self.printWebView = [[WebView alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, 800.0f, 11.0f)];
self.printWebView.UIDelegate = self;
[self.printWebView setShouldUpdateWhileOffscreen:YES];
此功能用于打开打印面板:
- (IBAction)onPrintButtonClicked:(id)sender
{
[[[[self.printWebView mainFrame] frameView] documentView] print:self];
}
打印面板打开时,将调用以下两种委托方法:
- (float)webViewFooterHeight:(WebView *)sender
{
return 50.0f;
}
- (void) webView:(WebView *)sender drawFooterInRect:(NSRect)rect
{
[[NSColor redColor] set];
NSRectFill(rect);
NSScrollView* view = sender.mainFrame.frameView.documentView.enclosingScrollView;
NSLog(@"Rect: %@, %@, %@", NSStringFromRect(sender.mainFrame.frameView.frame),
NSStringFromRect(sender.mainFrame.frameView.documentView.frame),
NSStringFromRect(view.documentVisibleRect));
}
打印预览中的页面更改时,所有打印帧均不会更改。代理被调用,但帧始终相同
如何确定页码?执行scrollview委托方法,并侦听滚动Web视图时遇到的scrollViewDidScroll方法。忘记添加“OS X”标记。OS X上没有此类委托。打印不会滚动。打印打印总视图,并根据需要分页。可能
[NSPrintOperation currentOperation].currentPage
会给你页码。@Willeke谢谢!这也是我同时发现的。实现scrollview委托方法,并侦听scrollViewDidScroll方法,当您滚动webView时,它会被点击。忘记添加“OS X”标记。OS X上没有此类委托。打印不会滚动。打印打印总视图,并根据需要分页。可能[NSPrintOperation currentOperation].currentPage
会给你页码。@Willeke谢谢!这也是我同时发现的。