{"id":13608098,"url":"https://github.com/pontedilana/php-weasyprint","last_synced_at":"2025-04-12T19:49:20.774Z","repository":{"id":37807378,"uuid":"386201076","full_name":"pontedilana/php-weasyprint","owner":"pontedilana","description":"PHP library allowing PDF generation or snapshot from an URL or an HTML page. Wrapper for Kozea/WeasyPrint","archived":false,"fork":false,"pushed_at":"2025-03-31T16:16:17.000Z","size":140,"stargazers_count":58,"open_issues_count":1,"forks_count":11,"subscribers_count":6,"default_branch":"develop","last_synced_at":"2025-04-04T01:15:51.217Z","etag":null,"topics":["pdf","php","weasyprint"],"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/pontedilana.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["endelwar"],"ko_fi":"endelwar"}},"created_at":"2021-07-15T07:20:19.000Z","updated_at":"2025-03-31T16:16:21.000Z","dependencies_parsed_at":"2024-01-14T06:29:40.434Z","dependency_job_id":"2f93c501-68e8-49e7-80be-557420965bc1","html_url":"https://github.com/pontedilana/php-weasyprint","commit_stats":{"total_commits":51,"total_committers":4,"mean_commits":12.75,"dds":0.05882352941176472,"last_synced_commit":"5c765de7d6acebf286f35d71f242e2771b0ab820"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pontedilana%2Fphp-weasyprint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pontedilana%2Fphp-weasyprint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pontedilana%2Fphp-weasyprint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pontedilana%2Fphp-weasyprint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pontedilana","download_url":"https://codeload.github.com/pontedilana/php-weasyprint/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248625501,"owners_count":21135513,"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":["pdf","php","weasyprint"],"created_at":"2024-08-01T19:01:24.235Z","updated_at":"2025-04-12T19:49:20.749Z","avatar_url":"https://github.com/pontedilana.png","language":"PHP","funding_links":["https://github.com/sponsors/endelwar","https://ko-fi.com/endelwar"],"categories":["PHP"],"sub_categories":[],"readme":"# PhpWeasyPrint\n\nPhpWeasyPrint is a PHP library allowing PDF generation from a URL or an HTML page.\nIt's a wrapper for [WeasyPrint](https://weasyprint.org/), a smart solution helping web developers to create PDF documents, available everywhere Python runs.\n\nYou will have to download and install WeasyPrint to use PhpWeasyPrint (version 56 or greater is recommended).\n\nThis library is massively inspired by [KnpLabs/snappy](https://github.com/KnpLabs/snappy), of which it aims to be a one-to-one substitute (`GeneratorInterface` is the same).\nSee \"[Differences with Snappy](#differences-with-snappy)\" section to see how the two differs\n\n## Installation using [Composer](https://getcomposer.org/)\n\n```bash\n$ composer require pontedilana/php-weasyprint\n```\n\n## Usage\n\n### Initialization\n\n```php\n\u003c?php\n\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse Pontedilana\\PhpWeasyPrint\\Pdf;\n\n$pdf = new Pdf('/usr/local/bin/weasyprint');\n\n// or you can do it in two steps\n$pdf = new Pdf();\n$pdf-\u003esetBinary('/usr/local/bin/weasyprint');\n```\n\n### Display the pdf in the browser\n\n```php\n$pdf = new Pdf('/usr/local/bin/weasyprint');\nheader('Content-Type: application/pdf');\necho $pdf-\u003egetOutput('https://www.github.com');\n```\n\n### Download the pdf from the browser\n\n```php\n$pdf = new Pdf('/usr/local/bin/weasyprint');\nheader('Content-Type: application/pdf');\nheader('Content-Disposition: attachment; filename=\"file.pdf\"');\necho $pdf-\u003egetOutput('https://www.github.com');\n```\n\n### Generate local pdf file\n\n```php\n$pdf = new Pdf('/usr/local/bin/weasyprint');\n$pdf-\u003egenerateFromHtml('\u003ch1\u003eBill\u003c/h1\u003e\u003cp\u003eYou owe me money, dude.\u003c/p\u003e', '/tmp/bill-123.pdf');\n```\n\n### Pass options to PhpWeasyPrint\n\n```php\n// Type weasyprint -h to see the list of options\n$pdf = new Pdf('/usr/local/bin/weasyprint');\n$pdf-\u003esetOption('encoding', 'utf8');\n$pdf-\u003esetOption('media-type', 'screen');\n$pdf-\u003esetOption('presentational-hints', true);\n$pdf-\u003esetOption('optimize-images', true);\n$pdf-\u003esetOption('stylesheet', ['/path/to/first-style.css', '/path/to/second-style.css']);\n$pdf-\u003esetOption('attachment', ['/path/to/image.png', '/path/to/logo.jpg']);\n```\n\n### Reset options\nOptions can be reset to their initial values with `resetOptions()` method.\n\n```php\n$pdf = new Pdf('/usr/local/bin/weasyprint');\n// Set some options\n$pdf-\u003esetOption('media-type', 'screen');\n// ..\n// Reset options\n$pdf-\u003eresetOptions();\n```\n\n### Timeouts\n\nA default timeout of 10 seconds is set for the WeasyPrint process to prevent orphaned or hanging processes.  \nThis is a defensive measure that applies in most cases and helps ensure system stability.\n\nYou can change the timeout with the `setTimeout()` method:\n\n```php\n$pdf = new Pdf('/usr/local/bin/weasyprint');\n$pdf-\u003esetTimeout(30); // 30 seconds\n```\n\nThe timeout can be disabled entirely using either of the following:\n\n```php\n$pdf-\u003esetTimeout(null);\n// or\n$pdf-\u003edisableTimeout();\n```\n\nThis is especially useful if you're running inside a *queue worker*, *job runner*, or other environments that already handle timeouts (e.g. Symfony Messenger, Laravel Queue, Supervisor).  \nDisabling the internal timeout in those cases avoids conflicts with higher-level timeout strategies.\n\n\u003e **Note:**  \n\u003e The `setTimeout()` method affects **both**:\n\u003e - how long the process is allowed to run before being forcibly stopped, and\n\u003e - the `--timeout` option passed to the WeasyPrint command-line tool.\n\u003e\n\u003e If you only want to disable WeasyPrint's own timeout (while keeping the execution time limit), use:\n\u003e\n\u003e ```php\n\u003e $pdf-\u003esetOption('timeout', null);\n\u003e ```\n\n## Differences with Snappy\n\nAlthough PhpWeasyPrint and Snappy are interchangeable, there are a couple of differences between the two, due to WeasyPrint CLI API:\n\n* WeasyPrint doesn't support multiple sources to be merged in one single output pdf, so only one input source (string or URL) is accepted in PhpWeasyPrint;\n* WeasyPrint version \u003e= 53 doesn't generate images, so image generation from HTML string or URL is possible only with WeasyPrint lower versions and an unsupported PhpWeasyPrint version (`Pontedilana\\PhpWeasyPrint\\Image` has been successfully tested with Weasyprint 52.5 on PhpWeasyPrint 0.13.0).\n\n## Bugs \u0026 Support\n\nIf you found a bug please fill a [detailed issue](https://github.com/pontedilana/php-weasyprint/issues) with all the following points.\nIf you need some help, please at least provide a complete reproducer, so we could help you based on facts rather than assumptions.\n\n* OS and its version\n* WeasyPrint, its version and how you installed it\n* A complete reproducer with relevant PHP and html/css/js code\n\nIf your reproducer is big, please try to shrink it. It will help everyone to narrow the bug.\n\n## Credits\n\nPhpWeasyPrint has been originally developed by the [Pontedilana](https://www.pontedilana.it) dev team.  \nSnappy has been originally developed by the [KnpLabs](https://knplabs.com) team.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpontedilana%2Fphp-weasyprint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpontedilana%2Fphp-weasyprint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpontedilana%2Fphp-weasyprint/lists"}