On Thu, Jan 20, 2011 at 9:24 AM, Dave Reed <davel...@mac.com> wrote: > I'm working on a document-based application that has a couple tabs. Most of > the tabs contain NSTableViews, NSTextFields, etc. > > I want to provide a way for the user to print the data contained in them > (just text, possibly with some grid lines), but not the actual table view. > I've read through (admittedly fairly quickly) the "Printing Topics for Cocoa" > document from Apple but it is more geared towards printing what you see on > the screen. > > I also may want to print different data depending on which tab the user is on. > > What is the appropriate way to do this? Do I override drawRect: for each tab > such as: > > - (void)drawRect:(NSRect)r { > if ( [NSGraphicsContext currentContextDrawingToScreen] ) { > [super drawRect:r] > } > else { > // somehow send drawing instructions for the text I want > } > } > > or do I somehow create an off screen view that I "draw" the text and grid > lines into?
I would take the first approach if (as is mentioned in the docs this example is from) drawing the view is mostly the same for both print and screen, except for a few embellishments (crop marks, footnotes, etc.) added to the print version. In your case, it sounds like you want to print something entirely different than what appears on-screen. In that case, I would take the second approach, in one of two ways: If what you want to print can be expressed in HTML (and it sounds like that may be the case), I'd create an off screen instance of WebView, feed it some HTML, and send it a -print message. In many cases this can be easier to maintain; you can take a template-based approach where the layout information is contained in an external template, which your app loads & "fills in" to generate the HTML it prints. That gives you the ability to tweak the layout & appearance using tools that are designed for just that (such as iWeb or Dreamweaver), rather than having to modify a custom -drawRect: for each change. Alternatively, you can subclass NSView with your customized -drawRect:, create an off screen instance of your subclass, and send it a -print message. sherm-- -- Cocoa programming in Perl: http://camelbones.sourceforge.net _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com