Skip navigation.
 
mlRe: How does -drawPageBorderWithSize: place pageHeader?
FROM : Tom Bunch
DATE : Thu Mar 13 01:01:03 2008

Mike,

I've messed around with this and boy has it been a head scratcher. 
Still haven't got it accounting properly for all combinations of 
scale, print size, and margins.

The default implementation of drawPageBorderWithSize: seems to want to 
print about 1/3 of the way from the margin to the edge of the page 
without regard to for printable area.

Instead of using -[NSPrinter imageRectForPaper:], see if -[NSPrintInfo 
imageablePageBounds] gives you what you're looking for.

Here's a little boost in code to get you part way done implementing 
drawPageBorderWithSize:, but as I noted, it has bugs w/ various page 
setup attributes.  If you should happen to fix them, lemme know!

    NSTextStorage *header, *footer;
   // stick something useful in header & footer

   NSRect pageRect = [self rectForPage:[[NSPrintOperation 
currentOperation] currentPage]];
   [header drawAtPoint:(NSPoint){pageRect.origin.x, pageRect.origin.y + 
[printInfo topMargin] / 3.0f}];
   [footer drawAtPoint:(NSPoint){pageRect.origin.x, pageRect.origin.y + 
borderSize.height - [footer size].height - [printInfo bottomMargin] / 
3.0f}];

Trying to put a topLeftHeader and a topRightHeader into one 
NSTextStorage using page with info and NSRightTabStops was kind of a 
pain.  I think if I do it again I'll just use separate text storages.

Hope this helps.

-Tom

On Mar 12, 2008, at 2:47 PM, Mike Wright wrote:

> I have an app (Universal, compiled using XCode 2.5, running on an 
> Intel iMac, under Leopard) that lets the user set page margins when 
> printing. It also lets them specify the printing of headers and 
> footers.
>
> The odd thing I'm seeing with this is that the placement of the 
> pageHeader string varies with the frame of the NSTextView subclass 
> that I'm printing.
>
> When the view frame's origin.y is set to the default value of 72, 
> the left end of the pageHeader is about a quarter-inch in, and the 
> entire header string has about a quarter-inch of space above it. 
> That works fine with my printer.
>
> As origin.y is reduced, the page header not only moves up--it also 
> expands the the left and right. With a topMargin of 14.4, the header 
> string has only about a sixteenth-inch of space to the left, to the 
> right, and above it. This moves it into the non-printable margins of 
> the paper.
>
> I implemented -drawPageBorderWithSize:borderSize in my printing view 
> (just calling super), and borderSize is always the paper size, 
> regardless of any changes in the view's frame due to the margin 
> settings.
>
> This width change looks like a bug to me, as does the vertical 
> position change. I can see no motivation for them, since all the 
> changes do is to push the header out of the printable area of the 
> paper. I've searched the documentation, but I don't see anything 
> about how the default method determines where to place the header.
>
> (I tried explicitly reducing borderSize in -
> drawPageBorderWithSize:borderSize, but the result is that the header 
> string still prints at the same left position--but with the overall 
> width of the string reduced, so that the date is moved to the right 
> by the amount that borderSize was reduced.)
>
> Unless someone can explain why it's not a bug, I guess I'll report it.
>
> And, even if it is, should I go ahead and try writing my own -
> drawPageBorderWithSize:borderSize--assuming that there won't be a 
> quick fix--or even any fix at all for Tiger?
>
> I'm not sure how to approach that, since NSPrinter's -
> imageRectForPaper:paperName is deprecated, with no replacement that 
> I can see. Is there some other way to find out where I should NOT 
> place the header and footer?
>
> As it is, the default footer shows up in Preview, but is down in the 
> middle of the bottom margin for my printer, so it doesn't actually 
> print. I assume that this is because the built-in -
> drawPageBorderWithSize:borderSize also has no way of determining the 
> printable area of a page. (I found a post asking about this from 3 
> Nov 2005, but no replies.)
>
> Thanks,
> Mike Wright
> http://www.idata3.com/
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>
>

Related mailsAuthorDate
mlHow does -drawPageBorderWithSize: place pageHeader? Mike Wright Mar 12, 22:47
mlRe: How does -drawPageBorderWithSize: place pageHeader? Tom Bunch Mar 13, 01:01
mlRe: How does -drawPageBorderWithSize: place pageHeader? Tom Bunch Mar 13, 01:02
mlRe: How does -drawPageBorderWithSize: place pageHeader? Mike Wright Mar 13, 02:31