{"id":23143127,"url":"https://github.com/cleancocoa/nstableview-printing","last_synced_at":"2025-08-11T23:03:44.179Z","repository":{"id":87401458,"uuid":"376241491","full_name":"CleanCocoa/NSTableView-Printing","owner":"CleanCocoa","description":"Example on how to print a NSTableView from your app but then also add text to the print-out.","archived":false,"fork":false,"pushed_at":"2022-03-29T15:45:24.000Z","size":692,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-20T10:11:42.579Z","etag":null,"topics":["macos","nsprintoperation","nstableview","printing"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CleanCocoa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-06-12T08:39:29.000Z","updated_at":"2024-05-08T11:44:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"60c9f77f-00e4-471c-a8c8-cbed54970588","html_url":"https://github.com/CleanCocoa/NSTableView-Printing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CleanCocoa/NSTableView-Printing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CleanCocoa%2FNSTableView-Printing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CleanCocoa%2FNSTableView-Printing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CleanCocoa%2FNSTableView-Printing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CleanCocoa%2FNSTableView-Printing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CleanCocoa","download_url":"https://codeload.github.com/CleanCocoa/NSTableView-Printing/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CleanCocoa%2FNSTableView-Printing/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269970086,"owners_count":24505458,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-11T02:00:10.019Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["macos","nsprintoperation","nstableview","printing"],"created_at":"2024-12-17T15:12:13.315Z","updated_at":"2025-08-11T23:03:44.165Z","avatar_url":"https://github.com/CleanCocoa.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NSTableView Printing Test\n\nThis is a demo project so you can check out how printing a table could work. \n\nThe goal here is to show tabular data on screen, and add text for print-outs.\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ca href=\"assets/screenshot.png\"\u003e\u003cimg src=\"assets/screenshot.png\" alt=\"Screenshot of the print dialog\"\u003e\u003c/a\u003e\u003cbr\u003e\u003csmall\u003ePrint dialog\u003c/small\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ca href=\"assets/printout.png\"\u003e\u003cimg src=\"assets/printout.png\" alt=\"Screenshot Preview.app showing the print result\"\u003e\u003c/a\u003e\u003cbr\u003e\u003csmall\u003ePDF result\u003c/small\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n## Discussion\n\n`NSView`-based printing is a bit odd since it prints whatever `NSView.draw(_:)` produces. We can customzie that by overriding the `draw` method. But for a table view? Embedding a stock standard table view in a custom view hierarchy sounds more promising.\n\nTo add a multi-line label on page, we cannot use the stock view-based printing options since the label is not part of the view hierarchy. We need to set up our own view hierarchy with all the to-be-printed views.\n\nFor the simple page layout used here, I picked a vertical `NSStackView`. This can be printed via `NSPrintOperation(view: stackView)` and then showing the print dialog for that. \n\nFor complex floating layouts, a `NSTextView` with an attributed string and maybe even a custom `NSLayoutManager` might be necessary. That's how you could, in theory, get text wrapped around images or small tables like Pages does it. \n\nActually recommended by other devs: use `WKWebView` and HTML. WebKit does a great job with complex layouts; just look at Safari. Then you can export the web view's content as PDF, and then use the PDF data for the print dialog directly. \n\nSee my accompanying blog post for details and a recap:  \n\u003chttps://christiantietze.de/posts/2021/06/printing-nstableview-with-label/\u003e\n\n## License\n\nThis code is in the Public Domain. Do what you want with it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcleancocoa%2Fnstableview-printing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcleancocoa%2Fnstableview-printing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcleancocoa%2Fnstableview-printing/lists"}