Re: Printing a view + landscape printing
Re: Printing a view + landscape printing
- Subject: Re: Printing a view + landscape printing
- From: Jean Suisse <email@hidden>
- Date: Tue, 22 Jan 2013 09:50:05 +0100
Thank you very much for your reply.
I can now print the right view. This view (Parent View) has only two large custom subviews in which I display graphics.
Currently, when I print Parent View, it is vertically spanned over two pages (which are printed) and horizontally spanned over two pages (which are not printed).
I tried to determine the size of the printable area of one page and to print a rectangle to materialize it, but I couldn't get it right. Here is the code:
NSPrintInfo* printInfo = [[NSPrintOperation currentOperation] printInfo];
NSSize paperSize = [printInfo paperSize];
NSSize printAreaSize = NSMakeSize(0.0, 0.0);
printAreaSize.height = paperSize.height - [printInfo topMargin] - [printInfo bottomMargin];
printAreaSize.width = paperSize.width - [printInfo leftMargin] - [printInfo rightMargin];
// I tried with and without the code below. If I divide by (scale*2.0) then the rectangle fits the paper but is displayed across two pages
float scale = [[[printInfo dictionary] objectForKey:NSPrintScalingFactor] floatValue];
paperSize.width = paperSize.width / (scale);
paperSize.height = paperSize.height / (scale);
[NSBezierPath strokeRect:NSMakeRect(0, 0, paperSize.width, paperSize.height)];
Currently, the size I get for the with paper size is way too large, even when divided by scale. This code is executed in parent view.
On 21 janv. 2013, at 18:36, Keary Suska <email@hidden> wrote:
> On Jan 21, 2013, at 8:17 AM, Jean Suisse wrote:
>
>> I have a non-document based application to which I would like to add printing support.
>> The main window (the one in the .xib created by default by Xcode) contains a split view.
>>
>> Currently, when printing, I get only the left pane of the split view (at best) or the control that has the focus (a textfield for instance) at worse.
>
> This likely has to do with which view is the first responder, and so is receiving a -print: action that has a nil target. Although that is how the menu is wired by default, I rarely find it useful. I generally use a custom method (one not implemented by any NSResponder class), so you can capture the print request.
>
>> What would be the minimum change to perform in order to get the view in the right side of the split view to print itself in landscape (I would like to offer landscape by default to the user) ? I am happy with the rest of the print flow the way it is.
>
> IIRC, unless otherwise specified, all built-in printing methods will use +[NSPrintInfo sharedPrintInfo] to determine page settings. You can customize your own NSPrintInfo and call +setSharedPrintInfo:. Or you can create your own printing session and pass the print info to it.
>
>> P.S.: I saw the Laying Out Page Content section in Printing Programming Guide, but I don't get how it is decided that the content of the view exceeds the size of a single page. I would prefer my view to be told to fit the selected page size (It is possible in my particular situation. I am printing graphics that can be resized to any size, to any ratio).
>
> AFAIK, fit-to-page is not a Cocoa printing system feature. You will have to do that yourself. In theory, the easiest way would be to determine the scaling factor needed and set that in the NSPrintInfo. NSPrintInfo will tell you the paper size and margins, from which you can determine the printable area, then dividing that by the view frame or bounds.
>
> HTH,
>
> Keary Suska
> Esoteritech, Inc.
> "Demystifying technology for your home or business"
>
_______________________________________________
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