{"id":26412980,"url":"https://github.com/spiritix/php-chrome-html2pdf","last_synced_at":"2025-05-15T11:02:11.897Z","repository":{"id":44339271,"uuid":"116250062","full_name":"spiritix/php-chrome-html2pdf","owner":"spiritix","description":"A PHP library for converting HTML to PDF using Google Chrome","archived":false,"fork":false,"pushed_at":"2025-03-28T22:31:21.000Z","size":378,"stargazers_count":149,"open_issues_count":12,"forks_count":31,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-09T21:34:14.340Z","etag":null,"topics":["html2pdf","htmltopdf","pdf","pdf-converter","php","puppeteer","puppeteer-pdf"],"latest_commit_sha":null,"homepage":"","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/spiritix.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2018-01-04T11:03:50.000Z","updated_at":"2025-04-21T07:50:23.000Z","dependencies_parsed_at":"2024-06-19T18:12:38.149Z","dependency_job_id":"ec3c0cf4-750e-40c2-a914-97e41842daa3","html_url":"https://github.com/spiritix/php-chrome-html2pdf","commit_stats":{"total_commits":95,"total_committers":11,"mean_commits":8.636363636363637,"dds":0.4842105263157894,"last_synced_commit":"ca4925b589cffa161e3a79650a3a403ffc89c655"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spiritix%2Fphp-chrome-html2pdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spiritix%2Fphp-chrome-html2pdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spiritix%2Fphp-chrome-html2pdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spiritix%2Fphp-chrome-html2pdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spiritix","download_url":"https://codeload.github.com/spiritix/php-chrome-html2pdf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254328385,"owners_count":22052632,"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":["html2pdf","htmltopdf","pdf","pdf-converter","php","puppeteer","puppeteer-pdf"],"created_at":"2025-03-17T22:53:42.135Z","updated_at":"2025-05-15T11:02:11.754Z","avatar_url":"https://github.com/spiritix.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Chrome HTML to PDF\n\nA PHP library for converting HTML to PDF using Chrome/Chromium.\n\n[![PHP Checks](https://github.com/spiritix/php-chrome-html2pdf/actions/workflows/php.yml/badge.svg)](https://github.com/spiritix/php-chrome-html2pdf/actions/workflows/php.yml)\n[![Node.js Checks](https://github.com/spiritix/php-chrome-html2pdf/actions/workflows/js.yml/badge.svg)](https://github.com/spiritix/php-chrome-html2pdf/actions/workflows/js.yml)\n[![Code Climate](https://codeclimate.com/github/spiritix/php-chrome-html2pdf/badges/gpa.svg)](https://codeclimate.com/github/spiritix/php-chrome-html2pdf)\n[![Total Downloads](https://poser.pugx.org/spiritix/php-chrome-html2pdf/d/total.svg)](https://packagist.org/packages/spiritix/php-chrome-html2pdf)\n[![Latest Stable Version](https://poser.pugx.org/spiritix/php-chrome-html2pdf/v/stable.svg)](https://packagist.org/packages/spiritix/php-chrome-html2pdf)\n[![Latest Unstable Version](https://poser.pugx.org/spiritix/php-chrome-html2pdf/v/unstable.svg)](https://packagist.org/packages/spiritix/php-chrome-html2pdf)\n[![License](https://poser.pugx.org/spiritix/php-chrome-html2pdf/license.svg)](https://packagist.org/packages/spiritix/php-chrome-html2pdf)\n\n_Contributors wanted!\nHave a look at the [open issues](https://github.com/spiritix/php-chrome-html2pdf/issues) and send me an email if you are interested in a quick introduction via Hangouts._\n\n## How it works\n\nThis library is based on [puppeteer](https://github.com/GoogleChrome/puppeteer), a headless Chrome Node API which is \nmaintained by the Chrome DevTools team.\n\nIt provides a simple PHP wrapper around the Node API, focused on generating beautiful PDF files.\n\nIn contrast to other HTML to PDF converters like [wkhtmltopdf](https://wkhtmltopdf.org/), the corresponding \n[PHP wrapper](https://github.com/spiritix/html-to-pdf) or similar libraries, it is based on a current Chrome version \ninstead of outdated and unmaintained WebKit builds. This library therefore fully supports CSS3, HTML5, SVGs, SPAs, \nand all the other fancy stuff people use these days.\n\n## Requirements\n\n- PHP 8.1+ with enabled program execution functions (proc_open) and 'fopen wrappers'\n- Node.js 18+ (for older Node.js versions use see [changelog](https://github.com/spiritix/php-chrome-html2pdf/blob/master/CHANGELOG.md))\n- A few [OS specific dependencies](https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix)\n\n## Installation\n\nPHP Chrome HTML to PDF can be installed via [Composer](http://getcomposer.org) by requiring the\n`spiritix/php-chrome-html2pdf` package in your project's `composer.json`.\nOr simply run this command:\n\n```sh\ncomposer require spiritix/php-chrome-html2pdf\n```\n\nThe required JS packages are installed automatically in the background.\n\n## Usage\n\nUsing this library is pretty straight forward. Decide for an input and an output handler, pass them to the converter, \nset some options if you like and depending on the output handler, proceed with the generated PDF file.\n\n```php\nuse Spiritix\\Html2Pdf\\Converter;\nuse Spiritix\\Html2Pdf\\Input\\UrlInput;\nuse Spiritix\\Html2Pdf\\Output\\DownloadOutput;\n\n$input = new UrlInput();\n$input-\u003esetUrl('https://www.google.com');\n\n$converter = new Converter($input, new DownloadOutput());\n\n$converter-\u003esetOption('landscape', true);\n\n$converter-\u003esetOptions([\n    'printBackground' =\u003e true,\n    'displayHeaderFooter' =\u003e true,\n    'headerTemplate' =\u003e '\u003cp\u003eI am a header\u003c/p\u003e',\n]);\n\n$converter-\u003esetLaunchOptions([\n      'ignoreHTTPSErrors' =\u003e true, \n      'headless' =\u003e true, \n      'executablePath' =\u003e '/usr/bin/google-chrome-stable', \n      'args' =\u003e [\n        '--no-sandbox',\n        '--disable-web-security',\n        '--font-render-hinting=none',\n        '--proxy-server=\"direct://\"',\n        '--proxy-bypass-list=*',\n        '--media-cache-size=0',\n        '--disk-cache-size=0',\n        '--disable-application-cache',\n        '--disk-cache-dir=/dev/null',\n        '--media-cache-dir=/dev/null'\n      ]\n   ]\n);\n\n\n$output = $converter-\u003econvert();\n$output-\u003edownload('google.pdf');\n```\n\n### Input handlers\n\nThe following input handlers are available:\n\n- StringInput - Accepts the HTML content as a string\n- UrlInput - Fetches the HTML content from an URL\n\n### Output handlers\n\nThe following output handlers are available:\n\n- StringOutput - Returns the binary PDF content as a string\n- FileOutput - Stores the PDF file on the server's file system\n- DownloadOutput - Forces the browser to download the PDF file\n- EmbedOutput - Forces the browser to embed the PDF file\n\n## Options\n\n- `scale` \u003c[number]\u003e Scale of the webpage rendering. Defaults to `1`.\n- `displayHeaderFooter` \u003c[boolean]\u003e Display header and footer. Defaults to `false`.\n- `headerTemplate` \u003c[string]\u003e HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them:\n    - `date` formatted print date\n    - `title` document title\n    - `url` document location\n    - `pageNumber` current page number\n    - `totalPages` total pages in the document\n- `footerTemplate` \u003c[string]\u003e HTML template for the print footer. Should use the same format as the `headerTemplate`.\n- `printBackground` \u003c[boolean]\u003e Print background graphics. Defaults to `false`.\n- `landscape` \u003c[boolean]\u003e Paper orientation. Defaults to `false`.\n- `pageRanges` \u003c[string]\u003e Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.\n- `format` \u003c[string]\u003e Paper format. If set, takes priority over `width` or `height` options. Defaults to 'Letter'.\n- `width` \u003c[string]\u003e Paper width, accepts values labeled with units.\n- `height` \u003c[string]\u003e Paper height, accepts values labeled with units.\n- `margin` \u003c[array]\u003e Paper margins, defaults to none.\n    - `top` \u003c[string]\u003e Top margin, accepts values labeled with units.\n    - `right` \u003c[string]\u003e Right margin, accepts values labeled with units.\n    - `bottom` \u003c[string]\u003e Bottom margin, accepts values labeled with units.\n    - `left` \u003c[string]\u003e Left margin, accepts values labeled with units.\n- `preferCSSPageSize` \u003c[boolean]\u003e Give any CSS @page size declared in the page priority over what is declared in width and height or format options. Defaults to `false`, which will scale the content to fit the paper size.\n- `omitBackground` \u003c[boolean]\u003e Hides default white background and allows capturing screenshots with transparency. Defaults to `false`.\n- `timeout` \u003c[number]\u003e Maximum time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout.\n- `mediaType` \u003c?[string]\u003e Changes the CSS media type of the page. The only allowed values are `'screen'`, `'print'` and `null`. Passing `null` disables media emulation.\n- `viewport` \u003c[array]\u003e\n    - `width` \u003c[number]\u003e page width in pixels.\n    - `height` \u003c[number]\u003e page height in pixels.\n    - `deviceScaleFactor` \u003c[number]\u003e Specify device scale factor (can be thought of as dpr). Defaults to `1`.\n    - `isMobile` \u003c[boolean]\u003e Whether the `meta viewport` tag is taken into account. Defaults to `false`.\n    - `hasTouch`\u003c[boolean]\u003e Specifies if viewport supports touch events. Defaults to `false`\n    - `isLandscape` \u003c[boolean]\u003e Specifies if viewport is in landscape mode. Defaults to `false`.\n- `pageWaitFor` \u003c[integer]\u003e Timeout in milliseconds to wait for.\n- `cookies`\u003c[array]\u003e Cookie objects to set.\n    \n\u003e **NOTE** `headerTemplate` and `footerTemplate` markup have the following limitations:\n\u003e 1. Script tags inside templates are not evaluated.\n\u003e 2. Page styles are not visible inside templates.\n\n\u003e **NOTE** By default, this library generates a pdf with modified colors for printing. Use the `-webkit-print-color-adjust`  property to force rendering of exact colors.\n\n## Troubleshooting\n\n- Make sure you've installed all [OS specific dependencies](https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix).\n- Manually set the path to your Node.js executable using the `$converter-\u003esetNodePath()` method.\n- Footer or header are not visible? See [here](https://github.com/spiritix/php-chrome-html2pdf/issues/66).\n\n## Contributing\n\nContributions in any form are welcome.\nPlease consider the following guidelines before submitting pull requests:\n\n- **Coding standard** - It's mostly PSR. \n- **Add tests!** - Your PR won't be accepted if it doesn't have tests.\n\n## License\n\nPHP Chrome HTML to PDF is free software distributed under the terms of the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspiritix%2Fphp-chrome-html2pdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspiritix%2Fphp-chrome-html2pdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspiritix%2Fphp-chrome-html2pdf/lists"}