Swastik
Swastik

Reputation: 2425

Provide print option from mac app

I have a Mac app. In my Mac app one of my screen has a scrollView 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.

Upvotes: 0

Views: 440

Answers (2)

Swastik
Swastik

Reputation: 2425

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

Upvotes: 0

Grady Player
Grady Player

Reputation: 14549

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.

Upvotes: 2

Related Questions