从mac app提供打印选项

时间:2011-04-29 05:55:42

标签: cocoa macos

我有一个Mac应用程序。在我的Mac应用程序中,我的一个屏幕上有一个scrollView,其中包含一个文本字段。在同一个屏幕上,我有一个需要提供打印选项的按钮。可以打印文本字段的文本。 “打印”按钮应调用Mac OS X打印对话框。我可以通过xib将按钮连接到第一响应者的打印选项来打开打印对话框,但是当我预览时,我看不到除打印按钮之外的任何文本。请帮忙。

2 个答案:

答案 0 :(得分:2)

查看NSPrintOperation类参考。 NSPrintOperation Class Reference

您可能需要将文本编写为NSView,其大小足以适合您的滚动视图内容...我从来没有必须从scrollView打印,所以我不知道。

看看

+ printOperationWithView:

你可能必须覆盖print:action,记住你将它发送给第一个响应者......并且应该转到你的NSDocument或NSApplication子类,但我可能会尝试在NSDocument中获取它基于文件,NSWindow(子类或代表),如果没有。

答案 1 :(得分:0)

我得到了答案。我正在使用以下代码,

- (void)print:(id)sender {

    // page settings for printing

    [self setPrintInfo:[NSPrintInfo sharedPrintInfo]];

    [printInfo setVerticalPagination:NSAutoPagination];
    float horizontalMargin, verticalMargin;

    horizontalMargin = 0;
    verticalMargin = -100;

    [printInfo setLeftMargin:horizontalMargin];
    [printInfo setRightMargin:horizontalMargin];
    [printInfo setHorizontallyCentered:YES];
    [printInfo setTopMargin:-600];
    [printInfo setBottomMargin:verticalMargin];
    [[NSPrintOperation printOperationWithView:sampleText] runOperation];
}