{"id":18031643,"url":"https://github.com/sanderdlm/chrome-pdf-bundle","last_synced_at":"2025-03-27T05:30:50.592Z","repository":{"id":43266429,"uuid":"356831086","full_name":"sanderdlm/chrome-pdf-bundle","owner":"sanderdlm","description":"Symfony bundle to generate PDFs with headless Chrome using chrome-php/chrome.","archived":false,"fork":false,"pushed_at":"2024-04-15T10:45:43.000Z","size":1125,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-20T09:05:38.812Z","etag":null,"topics":["chrome","chrome-php","pdf","symfony","symfony-bundle"],"latest_commit_sha":null,"homepage":"","language":"HTML","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/sanderdlm.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}},"created_at":"2021-04-11T09:58:56.000Z","updated_at":"2024-04-13T22:28:41.000Z","dependencies_parsed_at":"2024-04-11T09:44:12.590Z","dependency_job_id":null,"html_url":"https://github.com/sanderdlm/chrome-pdf-bundle","commit_stats":null,"previous_names":["dreadnip/chrome-pdf-bundle"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanderdlm%2Fchrome-pdf-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanderdlm%2Fchrome-pdf-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanderdlm%2Fchrome-pdf-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanderdlm%2Fchrome-pdf-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sanderdlm","download_url":"https://codeload.github.com/sanderdlm/chrome-pdf-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245791307,"owners_count":20672664,"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":["chrome","chrome-php","pdf","symfony","symfony-bundle"],"created_at":"2024-10-30T10:10:01.158Z","updated_at":"2025-03-27T05:30:49.869Z","avatar_url":"https://github.com/sanderdlm.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"ChromePdfBundle\n===============\n\nThe ChromePdfBundle is a Symfony bundle that leverages the [chrome-php/chrome](https://github.com/chrome-php/chrome) project to render HTML and save the output as a PDF file.\n\nInstallation\n------------\n\nWith [composer](https://getcomposer.org), require:\n\n`composer require dreadnip/chrome-pdf-bundle`\n\nConfiguration\n-------------\n\nThe bundle relies on a working, up-to-date Chrome/Chromium instance to work. You must specify the binary in your .env file.\n\n```yaml\n# .env or .env.local\nCHROME_BINARY=\"/usr/bin/chromium\"\n```\n\nUsage\n-----\n\nThe bundle registers two services:\n\n- `chrome_pdf.pdf_generator` allows you to generate pdf files from HTML strings. You can autowire the `PdfGenerator` class in your application to get started quickly.\n- `chrome_pdf.browser_factory` is the chrome-php/chrome BrowserFactory class offered as a service within your Symfony application. Use this if you want to fine-tune the PDF generation process. You can use the PdfGenerator class as a starting point and build your custom solution from that.\n\n### Basic example: render a pdf document in a controller\n\n```php\nuse Dreadnip\\ChromePdfBundle\\Service\\PdfGenerator;\nuse Symfony\\Component\\HttpFoundation\\BinaryFileResponse;\nuse Symfony\\Component\\HttpFoundation\\Response;\nuse Twig\\Environment;\n\nclass TestController extends AbstractController\n{\n    public function __invoke(PdfGenerator $pdfGenerator): Response\n    {\n        $html = $this-\u003erender('pdf.html.twig');\n\n        $path = $pdfGenerator-\u003egenerate($html, 'files/test.pdf');\n   \n        return new BinaryFileResponse($path);\n    }\n}\n```\n\n### Advanced example: render a pdf document in a controller with custom options\n\n```php\nuse Dreadnip\\ChromePdfBundle\\Service\\PdfGenerator;\nuse Symfony\\Component\\HttpFoundation\\BinaryFileResponse;\nuse Symfony\\Component\\HttpFoundation\\Response;\nuse Twig\\Environment;\n\nclass TestController\n{\n    public function __invoke(\n        Environment $twig,\n        PdfGenerator $pdfGenerator\n    ): Response {\n        $html = $twig-\u003erender('pdf.html.twig');\n\n        // Control everything by passing custom options\n        $printOptions = [\n            'printBackground' =\u003e true,\n            'displayHeaderFooter' =\u003e true,\n            'preferCSSPageSize' =\u003e true,\n            'headerTemplate'=\u003e \"\u003cdiv\u003e\u003c/div\u003e\",\n            'footerTemplate' =\u003e \"\u003cdiv\u003e\u003c/div\u003e\",\n            'scale' =\u003e 1.0,\n        ];\n        \n        // Setting headless to false helps you debug issues\n        $browserOptions = [\n            'headless' =\u003e false,\n        ];\n\n        $path = $pdfGenerator-\u003egenerate(\n            html: $html,\n            path: 'files/test.pdf',\n            printOptions: $options,\n            browserOptions: $browserOptions,\n            timeout: 5000\n        );\n\n        return new BinaryFileResponse($path);\n    }\n}\n```\n[Print options](https://github.com/chrome-php/chrome#print-as-pdf) can be used to control the rendering of the PDF.\n\n[Browser options](https://github.com/chrome-php/chrome#options) are available to control the headless Chrome instance that will be used to render the PDF. \n\nA list of all available options can be found in the chrome-php/chrome repository.\n\n### Base template\n\nThe bundle comes with a base template that can be extended to build PDFs with. This includes helpers for page lay-out and breaking. The template comes with two blocks `styles` for CSS and `content` for the actual PDF content.\n\n```html\n{% extends '@ChromePdf/base.html.twig' %}\n\n{% block content %}\n    \u003csection class=\"page page-one break-after\"\u003e\n        \u003ch1\u003eFirst page\u003c/h1\u003e\n        \u003cp\u003eLorem ipsum dolor sit amet, consectetur adipisicing elit. Dolores enim maxime quasi? Ab accusantium at commodi corporis, distinctio earum facilis harum ipsum maxime, nisi nostrum obcaecati odit officia quod voluptatem?\u003c/p\u003e\n    \u003c/section\u003e\n    \u003csection class=\"page page-two\"\u003e\n        \u003ch2\u003eSecond page\u003c/h2\u003e\n        \u003cp\u003eLorem ipsum dolor sit amet, consectetur adipisicing elit. Dolores enim maxime quasi? Ab accusantium at commodi corporis, distinctio earum facilis harum ipsum maxime, nisi nostrum obcaecati odit officia quod voluptatem?\u003c/p\u003e\n    \u003c/section\u003e\n{% endblock %}\n\n```\n\nCredits\n-------\n\nThis bundle is nothing more than a simple wrapper around the awesome [chrome-php/chrome](https://github.com/chrome-php/headless-chromium-php) project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanderdlm%2Fchrome-pdf-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsanderdlm%2Fchrome-pdf-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanderdlm%2Fchrome-pdf-bundle/lists"}