Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

renzil

macrumors newbie
Original poster
Aug 5, 2009
7
0
Hi, I need to launch the Mac equivalent of a Windows 'PrintDlg()' when I click on a button. From the Cocoa documentation, I can see that this is easily done given an NSView/NSWindow using the 'print' message.

Suppose I don't have an NSView/NSWindow. Is there a way to bring up a Print Panel without it? Or do I have to create one and then call print?

Edit: Basically, I have an image (or some external resource) that I would like to print, without displaying it in a window/view.
 
Hi, I need to launch the Mac equivalent of a Windows 'PrintDlg()' when I click on a button. From the Cocoa documentation, I can see that this is easily done given an NSView/NSWindow using the 'print' message.

Suppose I don't have an NSView/NSWindow. Is there a way to bring up a Print Panel without it? Or do I have to create one and then call print?

Edit: Basically, I have an image (or some external resource) that I would like to print, without displaying it in a window/view.

You don't have to display it: create an NSView in memory that "displays" the image and ask that to print. It should work even though the NSView is not in a window (and is not visible).
 
You don't have to display it: create an NSView in memory that "displays" the image and ask that to print. It should work even though the NSView is not in a window (and is not visible).

Did that in the following way:

NSRect frameRect = NSMakeRect(0.0f, 0.0f, 800.0f, 600.0f);
PrintView *view = [[PrintView alloc] initWithFrame:frameRect];
[view setHidden:YES]
[view print:nil];
[view release];

Here, PrintView is an extension of NSView and has a function 'initWithFrame' that invokes the super class' 'initWithFrame'.

Regardless of whether I call setHidden, the view is always shown. How do I hide it?

Also, I have overridden the 'drawRect' function to draw an image. Do I need to explicitly call 'drawRect' before calling 'print'?

Thanks for helping out.
 
Where is the view visible? It should only ever be visible if you've added it to a visible NSWindow?

Anyway overriding drawRect: is the correct thing to do: when the print system wants to print it sets up the correct context and asks your view to drawRect:. Whatever you draw is what gets printed.
 
OK, I got the view to work fine and I'm able to see my imported image in the panel's preview. However, when I select 'Open PDF in Preview', I get a dialog saying 'Processing page: 1', with a progress indicator. The progress indicator goes to 100%, but the PDF never opens. Even if I click 'Cancel' on this dialog, it still hangs. Any idea what could be causing it?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.