{"id":15169498,"url":"https://github.com/yii2tech/html2pdf","last_synced_at":"2025-10-01T02:31:17.598Z","repository":{"id":46525925,"uuid":"58051656","full_name":"yii2tech/html2pdf","owner":"yii2tech","description":"Yii2 component for HTML to PDF conversion","archived":true,"fork":false,"pushed_at":"2019-10-17T11:03:13.000Z","size":59,"stargazers_count":78,"open_issues_count":0,"forks_count":26,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-07-21T09:59:55.267Z","etag":null,"topics":["html","pdf","template","yii","yii2","yii2-extension"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yii2tech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["klimov-paul"],"patreon":"klimov_paul"}},"created_at":"2016-05-04T12:51:04.000Z","updated_at":"2023-12-26T13:56:10.000Z","dependencies_parsed_at":"2022-09-19T11:41:08.006Z","dependency_job_id":null,"html_url":"https://github.com/yii2tech/html2pdf","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/yii2tech/html2pdf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yii2tech%2Fhtml2pdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yii2tech%2Fhtml2pdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yii2tech%2Fhtml2pdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yii2tech%2Fhtml2pdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yii2tech","download_url":"https://codeload.github.com/yii2tech/html2pdf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yii2tech%2Fhtml2pdf/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277489015,"owners_count":25826632,"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-29T02:00:09.175Z","response_time":84,"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":["html","pdf","template","yii","yii2","yii2-extension"],"created_at":"2024-09-27T07:02:26.918Z","updated_at":"2025-10-01T02:31:17.236Z","avatar_url":"https://github.com/yii2tech.png","language":"PHP","funding_links":["https://github.com/sponsors/klimov-paul","https://patreon.com/klimov_paul"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/yii2tech\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://avatars2.githubusercontent.com/u/12951949\" height=\"100px\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eHTML to PDF conversion extension for Yii2\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\nThis extension provides basic support for HTML to PDF and PHP to PDF conversion.\n\nFor license information check the [LICENSE](LICENSE.md)-file.\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/yii2tech/html2pdf.svg)](https://packagist.org/packages/yii2tech/html2pdf)\n[![Total Downloads](https://img.shields.io/packagist/dt/yii2tech/html2pdf.svg)](https://packagist.org/packages/yii2tech/html2pdf)\n[![Build Status](https://travis-ci.org/yii2tech/html2pdf.svg?branch=master)](https://travis-ci.org/yii2tech/html2pdf)\n\n\nInstallation\n------------\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```\nphp composer.phar require --prefer-dist yii2tech/html2pdf\n```\n\nor add\n\n```json\n\"yii2tech/html2pdf\": \"*\"\n```\n\nto the require section of your composer.json.\n\n\u003e Note: you'll have to install software for the actual HTML to PDF conversion separately, depending on the\n  particular converter, you would like to use.\n\n\nUsage\n-----\n\nThis extension provides support for HTML to PDF and PHP to PDF conversion. It allows composition of the PDF files\nfrom HTML and via rendering PHP templates.\n\nExtension functionality is aggregated into `\\yii2tech\\html2pdf\\Manager` application component.\nApplication configuration example:\n\n```php\n\u003c?php\n\nreturn [\n    'components' =\u003e [\n        'html2pdf' =\u003e [\n            'class' =\u003e 'yii2tech\\html2pdf\\Manager',\n            'viewPath' =\u003e '@app/views/pdf',\n            'converter' =\u003e 'wkhtmltopdf',\n        ],\n    ],\n    ...\n];\n```\n\nFor the simple conversion you can use `\\yii2tech\\html2pdf\\Manager::convert()` and `\\yii2tech\\html2pdf\\Manager::convertFile()` methods:\n\n```php\n\u003c?php\n\n$html = \u003c\u003c\u003cHTML\n\u003chtml xmlns=\"http://www.w3.org/1999/xhtml\"\u003e\n\u003chead\u003e\n    \u003cmeta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003cp\u003eSimple Content\u003c/p\u003e\n\u003c/body\u003e\n\u003c/html\u003e\nHTML;\n\n// create PDF file from HTML content :\nYii::$app-\u003ehtml2pdf\n    -\u003econvert($html)\n    -\u003esaveAs('/path/to/output.pdf');\n\n// convert HTML file to PDF file :\nYii::$app-\u003ehtml2pdf\n    -\u003econvertFile('/path/to/source.html')\n    -\u003esaveAs('/path/to/output.pdf');\n```\n\nThe actual conversion result determined by particular converter used.\nYou may use `\\yii2tech\\html2pdf\\Manager::$converter` property for the converter setup.\n\nSeveral built-in converters are provided:\n\n - [yii2tech\\html2pdf\\converters\\Wkhtmltopdf](src/converters/Wkhtmltopdf.php) - uses [wkhtmltopdf](http://wkhtmltopdf.org/) utility for the conversion.\n - [yii2tech\\html2pdf\\converters\\Dompdf](src/converters/Dompdf.php) - uses [dompdf](https://github.com/dompdf/dompdf) library for the conversion.\n - [yii2tech\\html2pdf\\converters\\Mpdf](src/converters/Mpdf.php) - uses [mpdf](https://github.com/mpdf/mpdf) library for the conversion.\n - [yii2tech\\html2pdf\\converters\\Tcpdf](src/converters/Tcpdf.php) - uses [TCPDF](http://www.tcpdf.org) library for the conversion.\n - [yii2tech\\html2pdf\\converters\\Callback](src/converters/Callback.php) - uses a custom PHP callback for the conversion.\n\n**Heads up!** Most of the provided converters require additional software been installed, which is not provided by\nhis extension by default. You'll have to install it manually, once you decide, which converter you will use.\nPlease refer to the particular converter class for more details.\n\nYou may specify conversion options via second argument of the `convert()` or `convertFile()` method:\n\n```php\n\u003c?php\n\nYii::$app-\u003ehtml2pdf\n    -\u003econvertFile('/path/to/source.html', ['pageSize' =\u003e 'A4'])\n    -\u003esaveAs('/path/to/output.pdf');\n```\n\nYou may setup default conversion options at the `\\yii2tech\\html2pdf\\Manager` level:\n\n```php\n\u003c?php\n\nreturn [\n    'components' =\u003e [\n        'html2pdf' =\u003e [\n            'class' =\u003e 'yii2tech\\html2pdf\\Manager',\n            'viewPath' =\u003e '@app/pdf',\n            'converter' =\u003e [\n                'class' =\u003e 'yii2tech\\html2pdf\\converters\\Wkhtmltopdf',\n                'defaultOptions' =\u003e [\n                    'pageSize' =\u003e 'A4'\n                ],\n            ]\n        ],\n    ],\n    ...\n];\n```\n\n\u003e Note: the actual list of available conversion options depends on the particular converter to be used.\n\n\n## Template usage \u003cspan id=\"template-usage\"\u003e\u003c/span\u003e\n\nYou may create PDF files rendering PHP templates (view files), which composes HTML output.\nSuch files are processed as regular view files, allowing passing params and layout wrapping.\nMethod `\\yii2tech\\html2pdf\\Manager::render()` used for this:\n\n```php\n\u003c?php\n\nYii::$app-\u003ehtml2pdf\n    -\u003erender('invoice', ['user' =\u003e Yii::$app-\u003euser-\u003eidentity])\n    -\u003esaveAs('/path/to/output.pdf');\n```\n\nYou may use a shared layout for the templates, which can be setup via `\\yii2tech\\html2pdf\\Manager::$layout`.\n\nDuring each rendering view is working in context of `\\yii2tech\\html2pdf\\Template` object, which can be used to adjust\nlayout or PDF conversion options inside view file:\n\n```php\n\u003c?php\n/* @var $this \\yii\\web\\View */\n/* @var $context \\yii2tech\\html2pdf\\Template */\n/* @var $user \\app\\models\\User */\n$context = $this-\u003econtext;\n\n$context-\u003elayout = 'layouts/payment'; // use specific layout for this template\n\n// specify particular PDF conversion for this template:\n$context-\u003epdfOptions = [\n    'pageSize' =\u003e 'A4',\n    // ...\n];\n?\u003e\n\u003ch1\u003eInvoice\u003c/h1\u003e\n\u003cp\u003eFor: \u003c?= $user-\u003ename ?\u003e\u003c/p\u003e\n...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyii2tech%2Fhtml2pdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyii2tech%2Fhtml2pdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyii2tech%2Fhtml2pdf/lists"}