开发者

Provide print option from mac app

I have a Mac app. In my Mac app one of my screen has a scrollView开发者_Python百科 which contains a text field. On the same screen I have a button that needs to provide a print option. The text of the text field can be printed. Print button should call the Mac OS X print dialog box. I am able to open the print dialog box by connecting the button to the print option of the first responder through xib but when I preview I don't see any text except the print button. Please help.


check out the NSPrintOperation Class Reference. NSPrintOperation Class Reference

you will probably need to compose the text to a NSView that is large enough to fit your scroll view contents... I haven't ever had to print from a scrollView, so i don't know.

look at

+ printOperationWithView:

you will probably have to override the print: action, remember that you will be sending that to the first responder... and should fall through to your NSDocument or NSApplication subclass, but I would probably try to grab it at NSDocument if document based, NSWindow (subclass or delegate) if not.


I got the answer for this.I am using the below code,

- (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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜