{"id":19097791,"url":"https://github.com/aaronland/swift-webster","last_synced_at":"2026-01-29T09:02:55.124Z","repository":{"id":54420186,"uuid":"289754079","full_name":"aaronland/swift-webster","owner":"aaronland","description":"Swift package for generating a PDF file from a URL (rendered by WebKit).","archived":false,"fork":false,"pushed_at":"2024-10-02T23:47:23.000Z","size":32,"stargazers_count":2,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-08T14:37:52.701Z","etag":null,"topics":["pdf","swift","webkit"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aaronland.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}},"created_at":"2020-08-23T19:34:33.000Z","updated_at":"2024-12-27T10:20:42.000Z","dependencies_parsed_at":"2022-08-13T15:10:10.954Z","dependency_job_id":null,"html_url":"https://github.com/aaronland/swift-webster","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/aaronland/swift-webster","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronland%2Fswift-webster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronland%2Fswift-webster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronland%2Fswift-webster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronland%2Fswift-webster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aaronland","download_url":"https://codeload.github.com/aaronland/swift-webster/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronland%2Fswift-webster/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274128156,"owners_count":25226955,"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-09-08T02:00:09.813Z","response_time":121,"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":["pdf","swift","webkit"],"created_at":"2024-11-09T03:42:42.201Z","updated_at":"2026-01-29T09:02:55.044Z","avatar_url":"https://github.com/aaronland.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swift-webster\n\nSwift package for generating a PDF file from a URL (rendered by WebKit).\n\n## Example\n\n```\nimport Webster\n\nguard let source_url = URL(string: \"https://example.com\") else {\n    fatalError(\"Invalid source URL.\")\n}\n\nlet w = Webster()\n\nw.dpi = 72.0\nw.width = 11.0\nw.height = 8.5\nw.margin = 0.5\n\non_complete = func(result: Result\u003cData, Error) -\u003e Void {\n\n    if case .failure(let error) = result {\n        fatalError(\"Failed to generate PDF file, \\(error.localizedDescription)\")\n    }\n\n    if case .success(let data) = result {\n        // Do something with data here\n    }\n}\n\nw.render(source: source_url, completionHandler: on_complete)\n```\n\n## Notes\n\n### This package uses deprecated APIs\n\nThis package uses deprecated APIs notably [WebView](https://developer.apple.com/documentation/webkit/webview).\n\nSpecifically, this package is uses [NSPrintOperation](https://developer.apple.com/documentation/appkit/nsprintoperation) to render a `WebView`. Ideally I would like `NSPrintOperation` to print directly to a `Data` instance but it's not possible to do this. Instead the `render` method creates a temporary file, writes to it, reads the data and removes the temporary file on exit. This introduces extra overhead but, hopefully, keeps the interface a little more agnostic about how the resultant PDF document is used.\n\n### There is a WKWebView branch\n\nThere is a [wkwebview](https://github.com/aaronland/swift-webster/tree/wkwebview) branch that uses the newer [WKWebView](https://developer.apple.com/documentation/webkit/wkwebview) APIs however it does not work. I can not determine for sure if the problem is with my code or with Apple's MacOS APIs. It seems like the latter but I would be happy for it to be the former. This branch has two separate delegates, neither of which work as desired.\n\nThe [first](https://github.com/aaronland/swift-webster/blob/wkwebview/Sources/Webster/WKWebViewNSPrintDelegate.swift) calls `webView.printOperation` as recommended by the documentation. However when the `printOperation.run()` method is invoked it never completes. Apparently, I am supposed to invoke the `printOperation.runModal` method but that depends on a `NSWindow` instance which is not present in the final `webView` instance.\n\nThe [second](https://github.com/aaronland/swift-webster/blob/wkwebview/Sources/Webster/WKWebViewPDFDelegate.swift) calls `webView.createPDF` as recommended by the documentation but this produces a single PDF file the size of the final web page's dimensions. Maybe this is the expected behaviour?\n\nAny pointers or suggestions for how to address either of these issues would be welcome.\n\n## Credits\n\nThis build's on @msmollin's original [webster](https://github.com/msmollin/webster) and currently exists as a separate project because it is full of Swift Package Manager -isms and I am not sure what the best way to create a PR is yet.\n\n## See also\n\n* https://github.com/aaronland/webster-cli\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronland%2Fswift-webster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faaronland%2Fswift-webster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronland%2Fswift-webster/lists"}