xcode - Issues with printing a custom view to printer -



xcode - Issues with printing a custom view to printer -

working on printing custom view , having difficulties - hope can point me in right direction. have read above every apple document it's not working. created simple programme test printing, subclassed nsview (mainview) , added next drawrect method.

@implementation mainview - (void)drawrect:(nsrect)dirtyrect{ [super drawrect:dirtyrect]; nsmutableattributedstring *string = [[nsmutableattributedstring alloc] initwithstring:@"hi"]; [mystring drawinrect:dirtyrect]; }

i created custom view on window , set it's class mainview.

i run programme , text appears - far.

when click print pull down, dialog opens , preview shows entire window - includes upper bar min, max buttons. so, question #1, why have entire window vs. view?

second, created print routine in mainview , linked pulldown menu item it.

-(ibaction) printtheview{ nsrect r = [self bounds]; [[nsprintoperation printoperationwithview:self] runoperation]; [self datawithpdfinsiderect:r]; }

this yields nil in print preview. have tried various ways , nil has worked (ex: nssavepanel , beginsheetfordirectory... method). code above lastly attempt.

in summary, have 2 questions: 1) why first 1 printing entire window, vs view? 2) why won't custom print method work?

i have printed nstextview, can't seam one. suggestions/pointers/kicks appreciated.

thank you.

[edit]------

i have partially working. binding custom view through nsobject printtheview method. in ib, bound pull downwards menu item custom view object on window. works.

however, cannot bind button on window print method same way - i.e. cntl click , drag button object.

thoughts?

i resolved creating separate controller object. have following:

@interface viewcontroller : nsobject @interface mainview : nsview

made viewcontroller delegate mainview , created iboutlet custom view on window.

iboutlet mainview *view;

added print method viewcontroller:

-(ibaction)printtopdf:(id)sender{ [view printpdf]; }

added button window , linked printtopdf method in viewcontroller.

in mainview, added next print method:

-(void)printpdf{ nsrect r = [self bounds]; [[nsprintoperation printoperationwithview:self] runoperation]; [self datawithpdfinsiderect:r]; }

this works. remaining question why print menu items prints entire window vs view. have set separate question.

xcode cocoa printing nsview nsprintoperation

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -