Skip navigation.
 
mlRe: How does -drawPageBorderWithSize: place pageHeader?
FROM : Mike Wright
DATE : Thu Mar 13 02:31:45 2008

> On Mar. 12, 2008, at 20:01 , Tom Bunch wrote:

>> 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.

>
> Ah. I wonder how I missed that. That should do it.
>
> Thanks a bunch, Tom.  :-D
>
> I see that the docs for -imageablePageBounds says: "The imageable 
> bounds may extend past the edges of the sheet when, for example, a 
> printer driver specifies it so that borderless printing can be done 
> reliably." I'll have to take that into account.
>

>> 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.

>
> Thanks for the code, too.
>
> Actually, I decided not to do a footer, because it looks a little 
> odd when there's a 0.56" bottom margin. What I've done is to modify 
> the NSAttributedString  returned by [super pageHeader] so that I get 
> the job title at the left, the date in the center, and the page 
> number at the right, thus:
>
> - (NSAttributedString *)pageHeader
> {
>     // get the default header and footer
>     NSMutableAttributedString *mutablePageHeader = 
> [[[NSMutableAttributedString alloc] initWithAttributedString:[super 
> pageHeader]] autorelease];
>
>     NSMutableAttributedString *mutablePageFooter = 
> [[[NSMutableAttributedString alloc] initWithAttributedString:[super 
> pageFooter]] autorelease];
>     
>     // remove the first tab from the footer
>     NSRange range;
>     range.location = 0;
>     range.length = 1;
>     [mutablePageFooter deleteCharactersInRange:range];
>     
>     // remove the center tab from the header
>     range.location = [[self printJobTitle] length];
>     range.length = 1;
>     [mutablePageHeader deleteCharactersInRange:range];
>     
>     // append the footer string, with its leading tab, to the header
>     [mutablePageHeader appendAttributedString:mutablePageFooter];
>             
>     return mutablePageHeader;
> }
>
> Then I have -pageFooter return an empty string.
>
> Now I'll do all this within -drawPageBorderWithSize and try to get 
> it optimized for the printable area. I may even be able to align the 
> printJobTitle to the left margin of the page content, as one user 
> requested.
>
> Scaling is something I haven't done much with. Sounds like fun. (I 
> hate fun.)
>
> Cheers,
> Mike
>

>> 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.


[cut some text to reduce msg size]

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