Re: Problem printing a window
Re: Problem printing a window
- Subject: Re: Problem printing a window
- From: Scott Thompson <email@hidden>
- Date: Mon, 24 Oct 2005 16:36:28 -0500
On Oct 24, 2005, at 3:42 PM, Rick Hoge wrote:
I just added a print method to an application, and naively expected
the following to work:
-(IBAction)printDocument:(id)sender {
NSLog(@"Printing...");
[[self window] print:nil];
}
The above method is implemented in my NSWindowController subclass,
and is called when expected. I do get a printout of the window
(which is actually what I want), and it is even correctly scaled on
the page. The problem is that some parts of the window are
incorrectly rendered. The corners of a textured window contain
small black regions, the close/minimize/zoom buttons are displayed
at a very large size and cropped, and the file preview icon is
similarly enlarged and cropped.
It seems like some portions of the window are rendered by copying
bitmaps to the appropriate region, and this part of the rendering
is failing.
Does anyone have an idea of what might be happening here? I just
want to be able to make a printout of a document window and it was
very easy to get close, but I don't understand why the rendering is
bad.
Thanks for any suggestions,
The portions of the window that are drawing themselves improperly are
probably making the poor assumption that they are rendering to the
screen. They then do something like undo the current context
transform and draw in that coordinate space which doesn't work when
you go to the printer.
Your best bet may be to do something like implement
printOperationWithSettings: on your document and then do something
like (code typed into mail):
- (NSPrintOperation *)printOperationWithSettings:(NSDictionary *)
printSettings error:(NSError **)outError
{
NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
// Get the window from the first window controller (presumably
the document has only one window)
NSWindow *window = [[[self windowControllers] objectAtIndex: 1]
window];
NSView *printableView = [window contentView];
// Construct the print operation and setup Print panel
NSPrintOperation *printJob = [ NSPrintOperation
printOperationWithView:
printableView printInfo: printInfo];
return printJob;
}
This will give you only the content area of the window which may, or
may not be what you want. However, I suspect you can't rely on the
Window's structure view to draw itself properly to the printer.
Scott
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden