• 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: Off-screen Printing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Off-screen Printing


  • Subject: Re: Off-screen Printing
  • From: Jiri Volejnik <email@hidden>
  • Date: Wed, 1 Dec 2004 11:00:25 +0100


I am trying to create a program with some custom printing, involving layout and images that do not appear on any windows. The Cocoa APIs for printing are very powerful, and easy to follow, but they seem to be based on the assumption that a given view will be printed. Some view object has it's print method called. However, according to the documentation, the views have to be part of a window in order to function. Thus I can either create the view in a hidden (invisible) window, or off the side of a visible window, but not in the visible region. What is the best way to handle this type of "off screen" printing? What do people recommend? Am I working with a bad assumption, ie. that I need to use Views? Or that views have to be connected to a window to be printed?

Doesnt' matter how do you create views for printing. No window is needed for this purpose. Print command (from the menu) can be handled by a view, a window or a document, as you wish (-print:, -printDocument:). Of course you can invoke printing from anywhere else.


It's natural to use views for printing. You can use all the nice features they have - embeding another views, autoresizing etc. You can also design it using Interface Builder.

Below is a snippet from my test document class which triggers printing. -sheet is an accessor for my print view. The view is loaded from the document nib and is not placed in any window. However, it is of course possible to create a separate nib with a window and place the view into the window. I'm using this approach when I need instant preview.

Jirka

- (void)printDocument:(id)sender
{
	NSPrintInfo* pi = [self printInfo];

	// my sheet handles margins itself
	[pi setLeftMargin:0.0]; [pi setRightMargin:0.0];
	[pi setTopMargin:0.0]; [pi setBottomMargin:0.0];

	// my sheet covers a whole page
	NSView* view = [self sheet];
	NSSize size = [pi paperSize];
	[view setFrameSize:size];

	NSPrintOperation* op = [NSPrintOperation
		printOperationWithView:view
		printInfo:pi];
	[op runOperationModalForWindow:[self windowForSheet]
		delegate:self
		didRunSelector:
		@selector(printOperationDidRun:success:contextInfo:)
		contextInfo:0];
}

- (void)printOperationDidRun:(NSPrintOperation *)printOperation
	success:(BOOL)success contextInfo:(void *)info
{
	if (success) {
		// Can save updated NSPrintInfo, but only if you have
		// a specific reason for doing so
		// [self setPrintInfo: [printOperation printInfo]];
	}
}


_______________________________________________ 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
References: 
 >Off-screen Printing (From: Steve Sheets <email@hidden>)

  • Prev by Date: Re: Swapping isa's (was Re: Hex Edit controls (resknife))
  • Next by Date: Re: NSFileManager fun & games
  • Previous by thread: Re: Off-screen Printing
  • Next by thread: RE: Off-screen Printing
  • Index(es):
    • Date
    • Thread