I want to Print NSTableVIew data as multi page print preview but print preview shows only first few records rest pages are empty.I am using below code to print NStableView data.
let printInfo = NSPrintInfo.shared
printInfo.paperSize = NSSize(width: self.reporttableview.frame.width , height: 800.00)
printInfo.verticalPagination = .automatic
let operation: NSPrintOperation = NSPrintOperation(view: self.reporttableview, printInfo: printInfo)
operation.printPanel.options.insert([.showsPaperSize, .showsOrientation])
operation.run()
Above code working fine with minimum records like 30 -40 rows but when record is around 100 or more than 100 its only print first few records and rest pages are empty.Any help will be really appreciated.I have attached tableview and Print preview screen shots for better understanding.
- TableView Records: Table view screen shot
- Print Preview: Print preview screen shot You can see in above screen shot only first few pages having records rest are empty.And if I scroll table view in that case whole print Preview is empty. Empty print preview screen shot
I am not able to understand what I am doing wrong.
I had the same problem. I believe it is caused by the method AppKit uses to display NSTableViews efficiently. This seems to optimise, i.e. reduce, the memory load of large NSTableViews by only generating display data for about 3 "pages" of the view. To get the entire NSTableView to print, set the NSTableView instance property
var usesStaticContents: Bool { get set }
to true before printing (and return its value to false once printing is completed). I have tested this successfully on a table of 33 x A4 landscape pages and it works fine (although it takes ~5 seconds before the print panel is displayed).Here is the code that worked for me: