• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: printing a different representation than what is on the screen
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: printing a different representation than what is on the screen


  • Subject: Re: printing a different representation than what is on the screen
  • From: David Reed <email@hidden>
  • Date: Thu, 20 Jan 2011 19:58:08 -0500

On Jan 20, 2011, at 10:03 AM, Sherm Pendley wrote:

> On Thu, Jan 20, 2011 at 9:24 AM, Dave Reed <email@hidden> 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


Thanks for the advice. Yes, what I want to display is fairly different than what is displayed so the second approach is probably what I want. I hadn't thought of doing it via HTML, but that may be simpler than creating my own subclass of NSView. I just need to dust off my HTML skils that I haven't used in 10+ years.

Thanks,
Dave

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

References: 
 >printing a different representation than what is on the screen (From: Dave Reed <email@hidden>)
 >Re: printing a different representation than what is on the screen (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Re: iOS Pass NSManagedObjectContext from my app delegate
  • Next by Date: Re: Cleaning up weak references ( was Re: Odd Crash when adding table columns manually )
  • Previous by thread: Re: printing a different representation than what is on the screen
  • Next by thread: Re: printing a different representation than what is on the screen
  • Index(es):
    • Date
    • Thread