可可印刷 [英] Printing in Cocoa

查看:48
本文介绍了可可印刷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的观点非常适合A4页面.现在我要打印它.请注意,我没有使用drawRect或类似的东西,只是一个带有子视图和文本标签的普通视图.我的问题是我在该视图上有一些视图,我使用图层来放置背景颜色和围绕项的圆角矩形.子视图不会打印,但是所有文本标签都会打印.

I have made a view that pretty much fits A4 page. Now I want to print it. Note that I am not using drawRect or anything like that, just a normal view with subviews and text labels. My problem is that I have a few views on that view which I use layers to put background colors and rounded rects around the items. The subviews don't print, but all text labels print.

_printReport只是一个带有视图和一堆文本标签的纯窗口.

The _printReport is just a plain window with a view and bunch of text labels.

我在做什么错,我该怎么做呢?我真的不想做绘画,但是如果需要的话,我会做.

What am I doing wrong and how could I do this better ? I really don't want to do a drawrect but I will if I have to.

这是某人打印时发生的代码:

Here is the code that happens when someone prints :

- (void)printWorksheet {
    TJContact *worksheet = [[self.workSheets selectedObjects] objectAtIndex:0];
    if (worksheet == nil) return;

    _printReport = [[TJPrintReportWindowController alloc] initWithWindowNibName:@"TJPrintReportWindowController"];
    [self.printReport setCompany:self.company];
    [self.printReport setContact:worksheet];

    [self.printReport showWindow:self];
    [self.printReport becomeFirstResponder];
    [self.printReport.view becomeFirstResponder];
    NSPrintInfo* printInfo = [NSPrintInfo sharedPrintInfo];

    [printInfo setHorizontalPagination:NSFitPagination];
    [printInfo setVerticalPagination:NSFitPagination];
    [printInfo setHorizontallyCentered:YES];
    [printInfo setVerticallyCentered:YES];
    [printInfo setLeftMargin:20.0];
    [printInfo setRightMargin:20.0];
    [printInfo setTopMargin:10.0];
    [printInfo setBottomMargin:10.0];

    NSPrintOperation* printOperation = [NSPrintOperation printOperationWithView:self.printReport.view printInfo:printInfo];
    [printOperation setShowsPrintPanel:YES];
    [printOperation runOperationModalForWindow:[self window] delegate:nil didRunSelector:nil contextInfo:nil];
}

不确定是否有帮助,但是主视图确实将setWantsLayers设置为YES,这是我的装饰之一:

Not sure if this helps, but the main view does have setWantsLayers to YES, and here is one of my decorations :

CALayer *customerLayer = [self.customerView layer];
[customerLayer setCornerRadius:10];
[customerLayer setBackgroundColor:[NSColor colorWithDeviceWhite:0 alpha:0.30].CGColor];
[customerLayer setBorderColor:[NSColor blackColor].CGColor];
[customerLayer setBorderWidth:1.5];

当我在屏幕上显示窗口时,看起来就像我想要的那样,但是上面的矩形无法打印,但是上面的所有标签都可以打印.

When I display the window on screen, it looks just like I want it to, but the above round rect doesn't get printed, but all labels that are on top of it do.

推荐答案

图层未出现在打印中.我必须创建自己的NSView对象并执行drawRect函数以将其作为背景视图.然后它会自动打印出来,而无需执行任何操作.

Layers don't appear on printing. I had to make my own NSView object and do a drawRect function to put as background views. Then it printed out automatically without doing anything.

这篇关于可可印刷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆