{"id":15026731,"url":"https://github.com/spacetab-io/wkhtmltopdf-php","last_synced_at":"2025-04-09T20:21:31.265Z","repository":{"id":57056351,"uuid":"259689096","full_name":"spacetab-io/wkhtmltopdf-php","owner":"spacetab-io","description":"Non-blocking PHP wrapper for wkhtmltopdf built with AMP.","archived":false,"fork":false,"pushed_at":"2021-01-08T19:52:16.000Z","size":41,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T22:13:25.060Z","etag":null,"topics":["amphp","async","php","php74","wkhtmltoimage","wkhtmltopdf"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spacetab-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-28T16:15:39.000Z","updated_at":"2025-03-05T20:14:36.000Z","dependencies_parsed_at":"2022-08-24T14:52:54.892Z","dependency_job_id":null,"html_url":"https://github.com/spacetab-io/wkhtmltopdf-php","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacetab-io%2Fwkhtmltopdf-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacetab-io%2Fwkhtmltopdf-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacetab-io%2Fwkhtmltopdf-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacetab-io%2Fwkhtmltopdf-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spacetab-io","download_url":"https://codeload.github.com/spacetab-io/wkhtmltopdf-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247882171,"owners_count":21012011,"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","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":["amphp","async","php","php74","wkhtmltoimage","wkhtmltopdf"],"created_at":"2024-09-24T20:04:59.177Z","updated_at":"2025-04-09T20:21:31.243Z","avatar_url":"https://github.com/spacetab-io.png","language":"PHP","funding_links":[],"categories":["PDF"],"sub_categories":["Tunnel"],"readme":"Non-blocking WkHTMLtoPDF\n========================\n\n[![CircleCI](https://circleci.com/gh/spacetab-io/wkhtmltopdf-php/tree/master.svg?style=svg)](https://circleci.com/gh/spacetab-io/wkhtmltopdf-php/tree/master)\n[![codecov](https://codecov.io/gh/spacetab-io/wkhtmltopdf-php/branch/master/graph/badge.svg)](https://codecov.io/gh/spacetab-io/wkhtmltopdf-php)\n\nNon-blocking PHP wrapper for `wkhtmltopdf` and `wkhtmltoimage` built with [AMP](https://amphp.org).\n\n## Table of contents\n\n* [Features](#features)\n* [Why?](#why)\n* [Installation](#installation)\n* Usage\n    + [On your machine](#on-your-machine)\n        - [Simple cases](#simple-cases)\n        - [Parallel](#parallel)\n        - [Option Groups](#option-groups)\n    + [Docker](#docker)\n* [License](#license)\n\n## Features\n\n* An elegant interface to usage\n* Create PDF files from HTML or URI strings\n* Create Image files from HTML or URI string\n* Faster than others because can be run in parallel (native)\n* In-the-box your can use `OptionGroup` feature to group options for different cases  \n\n## Why\n\nExisting wrappers are slow, uses blocking API and does not have a normal object-oriented interface (for options).\n\nIt prevents to write fast and more elegant programming code. \n\n## Installation\n\n```bash\ncomposer require spacetab-io/wkhtmltopdf\n```\n\n## Usage\n\n### On your machine\n#### Simple cases\n\n1. Create a PDF file from HTML string and save it to current directory:\n\n```php\nuse Amp\\Loop;\nuse Spacetab\\WkHTML;\n\nLoop::run(static fn() =\u003e \n  yield WkHTML\\ToPDF::new()-\u003efromHtml('\u003cp\u003ehello world\u003c/p\u003e')-\u003easFile('hi.pdf')\n);\n```\n\n2. Create a PDF file from URI and save it to current directory:\n\n```php\nuse Amp\\Loop;\nuse Spacetab\\WkHTML;\n\nLoop::run(static fn() =\u003e \n  yield WkHTML\\ToPDF::new()-\u003efromUrl('https://google.com')-\u003easFile('google.pdf')\n);\n```\n\n3. Create a PDF file with custom options:\n\n```php\nuse Amp\\Loop;\nuse Spacetab\\WkHTML;\nuse Spacetab\\WkHTML\\OptionBuilder;\n\nLoop::run(static function () {\n  $option = new OptionBuilder\\PDF();\n  $option-\u003eaddGrayscale();\n\n  yield WkHTML\\ToPDF::new()-\u003efromUrl('https://google.com')-\u003easFile('google.pdf');\n});\n```\n\nNote: By default uses `UTF-8` encoding.\n\n#### Parallel\n\nIt simple! Right?\n\n```php\nLoop::run(static fn() =\u003e\n    yield [\n        WkHTML\\ToPDF::new()-\u003efromHtml('\u003cp\u003ehi1\u003c/p\u003e')-\u003easFile('hi1.pdf'),\n        WkHTML\\ToPDF::new()-\u003efromHtml('\u003cp\u003ehi2\u003c/p\u003e')-\u003easFile('hi2.pdf'),\n        WkHTML\\ToPDF::new()-\u003efromHtml('\u003cp\u003ehi3\u003c/p\u003e')-\u003easFile('hi3.pdf'),\n    ]\n);\n```\n\n#### Option Groups\n\nSo, if you work with many reports or create PDF files with set of different options \nyou can be attempt to use option groups. Sample:\n\n```php\nuse Amp\\Loop;\nuse Spacetab\\WkHTML;\nuse Spacetab\\WkHTML\\OptionBuilder;\nuse Spacetab\\WkHTML\\OptionBuilder\\OptionBuilderInterface;\nuse Spacetab\\WkHTML\\OptionGroup\\OptionGroupInterface;\n\nLoop::run(static function () {\n    $pdf = new WkHTML\\ToPDF(new class implements OptionGroupInterface {\n        public function __invoke(): OptionBuilderInterface {\n            $option = new OptionBuilder\\PDF();\n            $option-\u003eaddGrayscale();\n\n            return $option;\n        }\n    });\n\n    yield $pdf-\u003efromUrl('https://google.com')-\u003easFile('google.pdf');\n});\n```   \n\n### Docker\n\nFor usage in Docker your can like to use this image:\nhttps://github.com/spacetab-io/docker-amphp-php\n\n```Dockerfile\nFROM spacetabio/amphp-alpine:7.4-wkhtmltopdf-1.1.0\n\nCOPY * /app\n\n# cli commands should be created in the responsible service. \nCMD [\"bin/service\", \"run\"]\n```\n\nThis library tested in Docker container above in Circle CI.\n\n## License\n\nThe MIT License\n\nCopyright © 2021 spacetab.io, Inc. https://spacetab.io\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspacetab-io%2Fwkhtmltopdf-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspacetab-io%2Fwkhtmltopdf-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspacetab-io%2Fwkhtmltopdf-php/lists"}