首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用NSPrintOperation添加header?

如何使用NSPrintOperation添加header?
EN

Stack Overflow用户
提问于 2012-11-23 11:25:24
回答 1查看 1K关注 0票数 1

我想为我的Mac应用程序打印带有页眉和页脚(页码)的myWebView内容。到目前为止,我可以使用以下代码(从这个链接Printing multiple pages in Objective-C)打印myWebView的内容。

代码语言:javascript
复制
- (IBAction)sendToPrinter:(id)sender {
    NSPrintInfo *printInfo;
    NSPrintInfo *sharedInfo;
    NSPrintOperation *printOp;
    NSMutableDictionary *printInfoDict;
    NSMutableDictionary *sharedInfoDict;
    NSDictionary *printSettings;
    sharedInfo = [NSPrintInfo sharedPrintInfo];
    sharedInfoDict = [sharedInfo dictionary];
    printInfoDict = [NSMutableDictionary dictionaryWithDictionary:sharedInfoDict];
    [printInfoDict setObject:NSPrintSpoolJob forKey:NSPrintJobDisposition];
    printInfo = [[NSPrintInfo alloc] initWithDictionary: printInfoDict];
    [printInfo setHorizontalPagination: NSFitPagination];
    [printInfo setVerticalPagination: NSAutoPagination];
    [printInfo setVerticallyCentered:NO];
    [printInfo setLeftMargin:36];
    [printInfo setRightMargin:36];
    [printInfo setTopMargin:72];
    [printInfo setBottomMargin:72];
    [printInfo setScalingFactor:1.0];
    [[printInfo dictionary] setValue:[NSNumber numberWithBool:YES] forKey:NSPrintHeaderAndFooter];
    [[printInfo dictionary] addEntriesFromDictionary:printSettings];
PrintTextView *printView = [[PrintTextView alloc] initWithFrame:[printInfo imageablePageBounds]];
    printView.printJobTitle = @"Title of page to be printed inside the header"; 
    NSView *webViewContent = [[[myWebView mainFrame] frameView] documentView];
    printOp = [NSPrintOperation printOperationWithView:webViewContent printInfo: printInfo];
    [printOp runOperation];
}

我已经将PrintTextView类添加到我的项目中。我一直在阅读OSX库文档和NSPrintOperation方法,但到目前为止,作为一个新手,我无法弄清楚如何添加页眉和页脚。感谢您的帮助,任何示例代码或指导。

EN

回答 1

Stack Overflow用户

发布于 2015-04-27 20:35:48

按照CTMacUser的建议使用WebUIDelegate方法

代码语言:javascript
复制
#pragma mark - WebUIDelegate Methods

- (float)webViewHeaderHeight:(WebView *)sender
{
    return 20.0;
}

- (void)webView:(WebView *)sender drawHeaderInRect:(NSRect)rect
{
    NSString *headerString = @"Title of page to be printed inside the header";
    [headerString drawInRect:rect];    
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13522702

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档