• 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: Print / Save an NSView in a given size
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Print / Save an NSView in a given size


  • Subject: Re: Print / Save an NSView in a given size
  • From: Jens Beuckenhauer <email@hidden>
  • Date: Mon, 15 Jan 2007 16:21:51 +0100

Thank you very much for your help!!!

it helped me... I can now print and  save PDF/EPS in the desired sizes.

But what I don't understand is:

1. I want to save a rectangle or square or whatever in a TIFF-file. It should be 3 x 3 cm at printing.
BUT: The user should be able to define the resolution of the TIFF file by entering a value in a textfield.
For example: 600dpi and a 3 x 3 cm square.


All files generated by my code have 72 dpi. How can I change this?

A totally different problem had occured yesterday:

2. I have a textfield, in that the user should enter a 13 character- long number-code. I use a formatter for that.
It works when I hit enter in the textfield or when I use TAB. But I also have a button that generates the same action as the ENTER key in
the textfield. When I click it, the value of the textfield is not verified. I haven't found a way to achive this (And I don't know what's a keyword to look for)...


I tried to end the editing, but the entry gets deleted, what I don't want...

Thank you for your help

Jens Beuckenhauer
email@hidden

Am 15.01.2007 um 03:55 schrieb Marc Wan:

On 1/15/07, email@hidden <email@hidden> wrote:
Hello,

how can I print / save the content of an NSView in a given size (e.g.
3 x 3cm)?

so, I'm not 100% clear on what you're asking, but if i'm reading your message correctly, you want to:

1 - render some NSView data
2 - print it in a 3x3cm square
3 - print as PDF

And it sounds like you know how to do 1 and 3, so it's just really
step 2 that's the tricky part.

The good news is that it's not really hard.  As far as I understand
it (and testing in my program seems to confirm this), printing output
defaults to 72dpi.  Soooo, if you want to print at a different
resolution, you just need to scale the bounds of your NSView (not the
frame, just the bounds).

So, if you know your output rect is 200x200 pixels, then that would
become ~2.8 inches or so, or about 7.1cm.  To make this fit within
3cm, you would just add the following somewhere in your PRINTER
NSView:

/**
* I.E. printingSize = NSMakeSize(1.18, 1.18)  (1.18" = 3cm)
*/
- (void)adjustSizingForPrinting: (NSSize)printingSize
{
NSSize outputSize = NSMakeSize(200, 200);  // 200x200 pixel output
int dpi;

if (outputSize.width / outputSize.height >= (printingSize.width /
printingSize.height))
{
  dpi = (int)(outputSize.width / printingSize.width);
}
else
{
  dpi = (int)(outputSize.height / printingSize.height);
}

NSSize cs = [self frame].size;
NSSize nn = NSMakeSize(cs.width * dpi / 72, cs.height * dpi / 72);

[self setBoundsSize: nn];
}


The extra IF state at the top of this code is just there to help handle rectangular shapes, etc. You just need to add a call to [self adjustSizingForPrinting: ....] before you print.

The strategy is to just resize your bounds so that your drawing
pixels end up as the desired size.  The printing engine takes care of
matching it to device resolution based on capabilities and user print
settings (quality, etc).  It's actually extremely cool.


Jens Beuckenhauer
email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: 
 >Print / Save an NSView in a given size (From: email@hidden)
 >Re: Print / Save an NSView in a given size (From: "Marc Wan" <email@hidden>)

  • Prev by Date: Re: See-through effect (ala Terminal, iPhoto HUD windows, Disco)
  • Next by Date: Re: Fastest way to check for new files in a folder
  • Previous by thread: Re: Print / Save an NSView in a given size
  • Next by thread: StatusItem for PreferencePane
  • Index(es):
    • Date
    • Thread