How do I print the data from a tableview

I have looked all over and can’t seem to locate any info, probably not searching correctly, on how to print a tableview’s data out in a table format with header rows. Any assistance would be greatly appreciated.


bumping my own thread…anyone have a solution, or even a reference that I am unaware of that I can go read my self?

Thanks! :smiley:

Tables have a print: action method. Make a button, control-click-drag from the button to the table, and click in the circle next to print: in the dialog.

Thanks, but I think that doesn’t inlcude the header row when printing, at least I haven’t found a way to get it to. Also, do you know of a way to get all the columns to fit on the page? I have 7 columns that I need to fit.

Iappreciate the help :slight_smile:

It should give the header row OK, but if you want to paginate, you have to do that yourself. I’ve never tried it so I don’t know what’s involved: looks like you need to consult “Printing Programming Topics for Cocoa” in Xcode Help.

Thanks for the assistance and the point to documentation. I am still learning all this.


Hi Mark,

here is a workaround for printing a table:

  1. Put a box from IB under the table view. So you will not print the table itself but the contents of the box (i.e. the table)

  2. Write the script:

property theView : missing value
	-- IB Actions (button clicks)
	on thePrint_(sender)
	end thePrint_

  1. Bind the box to the variable theView – for example

  2. Bind the print button to the action handler thePrint_(sender) – for example

  3. Use the following code; test some parameters.

on doPrinting()
		set mySharedPrintInfo to current application's NSPrintInfo's sharedPrintInfo()
		mySharedPrintInfo's setLeftMargin_(20.0)
		mySharedPrintInfo's setRightMargin_(0.0)
		mySharedPrintInfo's setTopMargin_(20.0)
		mySharedPrintInfo's setBottomMargin_(10.0)
		mySharedPrintInfo's setOrientation_(0)
		mySharedPrintInfo's setHorizontalPagination_(1)
		mySharedPrintInfo's setVerticalPagination_(0)
		mySharedPrintInfo's setVerticallyCentered_(0)
		mySharedPrintInfo's setHorizontallyCentered_(1)
		set thePrintOp to current application's NSPrintOperation's printOperationWithView_printInfo_(theView, mySharedPrintInfo)
		thePrintOp's runOperation
	end doPrinting



Model: iMac
Browser: Safari 525.13
Operating System: Mac OS X (10.6)

Thanks Heiner! I will give that a try.

Much appreciated,