开发者

Printing the Data in a NSTableView

How would print what is in my NSTableView? The View uses core data so everything is stored a开发者_StackOverflownd can be grabbed as an NSArray. But how would I go about printing it out? At the moment when you click the print button it just seems to take a picture of the view and print that.


Yes, this works exactly as documented. The view is asked for its PDF representation (which, for an unmodified table view, is exactly what you see on screen), then this gets printed.

A view's drawing can be customized for printing versus on-screen drawing, but for a table view, this is more trouble than it's worth.

It might be easiest to generate an HTML representation of the table, then print that. You can use WebKit or just a plain NSAttributedString and off-screen NSTextView. The trick there is to generate the HTML, create an attributed string with the HTML data (there's a method just for that), then hand that to the off-screen text view. The text view would be sized as desired, then you just tell it to print. This gives you control over pagination as WebKit doesn't currently support the print-specific parts of CSS (in other words, it's "screen-only").


What I've done is taken the data and drawn it to a NSView based object in a way that the end-user would want to print. The user then prints that. it's in the docs.

I like Joshua Nozzi's idea, probably much simpler than custom drawing...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜