开发者

Objective C Printing: How to set header content?

I want to print a specific NSView. When I do this, I wish to add content to the header of the print page.

e.g. If the NSView contains a picture of a cat, when I press print, print preview shows up 开发者_运维百科with the picture of the cat. I want the print out to be a picture of a cat, with the caption: "Cat" in the header, which I do not want visible on the original NSView.

Also, if this is possible, is it also possible to add images too?

Thanks!


You can overwrite the method - (NSAttributedString *)pageHeader in your NSView subclass. See Apple's documentation here.

Note that headers are generated only if the user defaults contain the key NSPrintHeaderAndFooter with the value YES.

As for images, those can be added to a NSAttributedString using a NSTextAttachment.


If you want to draw things differently on the screen than the printer, you can use the isDrawingToScreen method in your drawRect: method.

Eg:

if (![[NSGraphicsContext currentContext] isDrawingToScreen]) {
//draw printer headers and images
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜