{"id":14974435,"url":"https://github.com/nahidulhasan/laravel-pdf","last_synced_at":"2025-04-10T02:22:35.448Z","repository":{"id":53764322,"uuid":"127262327","full_name":"nahidulhasan/laravel-pdf","owner":"nahidulhasan","description":"A Simple package for easily generating PDF documents from HTML. This package is specially for laravel but you can use this without laravel.","archived":false,"fork":false,"pushed_at":"2020-12-12T09:26:47.000Z","size":37,"stargazers_count":88,"open_issues_count":4,"forks_count":14,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-03T00:04:25.611Z","etag":null,"topics":["easily","html2pdf","laravel","laravel-5-package","laravel-html2pdf","laravel-package","laravel-pdf","laravel5","package","pdf","pdf-converter","pdf-generation","wkhtmltopdf"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nahidulhasan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-29T08:36:40.000Z","updated_at":"2024-08-30T15:37:29.000Z","dependencies_parsed_at":"2022-08-13T02:50:48.788Z","dependency_job_id":null,"html_url":"https://github.com/nahidulhasan/laravel-pdf","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nahidulhasan%2Flaravel-pdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nahidulhasan%2Flaravel-pdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nahidulhasan%2Flaravel-pdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nahidulhasan%2Flaravel-pdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nahidulhasan","download_url":"https://codeload.github.com/nahidulhasan/laravel-pdf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248143234,"owners_count":21054733,"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":["easily","html2pdf","laravel","laravel-5-package","laravel-html2pdf","laravel-package","laravel-pdf","laravel5","package","pdf","pdf-converter","pdf-generation","wkhtmltopdf"],"created_at":"2024-09-24T13:50:33.660Z","updated_at":"2025-04-10T02:22:35.412Z","avatar_url":"https://github.com/nahidulhasan.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel-Html2Pdf\n\n\n[![Latest Stable Version](https://poser.pugx.org/nahidulhasan/html2pdf/v/stable)](https://packagist.org/packages/nahidulhasan/html2pdf)\n[![Total Downloads](https://poser.pugx.org/nahidulhasan/html2pdf/downloads)](https://packagist.org/packages/nahidulhasan/html2pdf)\n[![Latest Unstable Version](https://poser.pugx.org/nahidulhasan/html2pdf/v/unstable)](https://packagist.org/packages/nahidulhasan/html2pdf)\n[![License](https://poser.pugx.org/nahidulhasan/html2pdf/license)](https://packagist.org/packages/nahidulhasan/html2pdf)\n\n\n\n\u003e A Simple package for easily generating PDF documents from HTML.This package is specially for laravel but you can use this without laravel.\n\n\n## Installation\n\n#### Install wkhtmltopdf \n\nThis was tested on:\n\n- Ubuntu 14.04 x64\n- Ubuntu 16.04 x64\n\n```sh\nsudo apt-get update\nsudo apt-get install xvfb libfontconfig wkhtmltopdf\n```\n\n#### For docker \n```\nRUN apt-get update \u0026\u0026 apt-get install xvfb libfontconfig wkhtmltopdf\n```\n\n#### Upddate Composer\n```\ncomposer require nahidulhasan/html2pdf\n```\n\nIf laravel version \u003c 5.5, add the ServiceProvider to the providers array in config/app.php\n\n    NahidulHasan\\Html2pdf\\Html2pdfServiceProvider::class,\n\nYou can optionally use the facade for shorter code. Add this to your facades:\n\n    'Pdf'  =\u003e NahidulHasan\\Html2pdf\\Facades\\Pdf::class,\n\n## Basic Usage\n\nTo create PDF add something like this to one of your controllers.\n\n```php\nuse NahidulHasan\\Html2pdf\\Facades\\Pdf;\n\n$document = Pdf::generatePdf('\u003ch1\u003eTest\u003c/h1\u003e');\n\n```\n\nYou can also create PDF from directly calling laravel blade file. Suppose you have a mail template named greeting in view/mails folder and want to send parameter then you have to call generatePdf method as described in below\n\n```php\n\n\u003c!-- mail template stored in resources/views/mails/greeting.blade.php --\u003e\n\n$document =  Pdf::generatePdf(view('mails.greeting', ['name' =\u003e 'James', 'testVar' =\u003e 'demo']));\n\n\n```\n\nNow If you want to send mail to your client attaching pdf then you can follow this code\n\n```php\n/**\n * Build the message.\n *\n * @return $this\n */\npublic function build()\n{\n    return $this-\u003efrom('username@gmail.com')\n                -\u003eview('mails.demo')\n                -\u003eattachData($document, 'Invoice.pdf');\n}\n  \n```\n\n### Download pdf\n\nSave the PDF to a file in a specific folder, and then download  it\n\n``` \nuse NahidulHasan\\Html2pdf\\Pdf;\n\n$obj = new Pdf();\n\n$html = '\u003chtml\u003e\u003cbody\u003e'\n    . '\u003cp\u003ePut your html here, or generate it with your favourite '\n    . 'templating system.\u003c/p\u003e'\n    . '\u003c/body\u003e\u003c/html\u003e';\n\n$invoice = $obj-\u003egeneratePdf($html);\n\ndefine('INVOICE_DIR', public_path('uploads/invoices'));\n\nif (!is_dir(INVOICE_DIR)) {\n    mkdir(INVOICE_DIR, 0755, true);\n}\n\n$outputName = str_random(10);\n$pdfPath = INVOICE_DIR.'/'.$outputName.'.pdf';\n\n\nFile::put($pdfPath, $invoice);\n\n$headers = [\n    'Content-Type' =\u003e 'application/pdf',\n    'Content-Disposition' =\u003e  'attachment; filename=\"'.'filename.pdf'.'\"',\n];\n\nreturn response()-\u003edownload($pdfPath, 'filename.pdf', $headers);\n\n```\n\n### Other Usage \n\nIt is also possible to use the following methods :\n\n``` pdf::stream('\u003ch1\u003eTest\u003c/h1\u003e')  ```  Open the PDF file in browser \n\n\n### Running without Laravel\n\nYou can use this library without using Laravel.\n\nExample:\n\n```\nuse NahidulHasan\\Html2pdf\\Pdf;\n\n$obj = new Pdf();\n$document = $obj-\u003egeneratePdf('\u003ch1\u003eTest\u003c/h1\u003e');\n```\n\n### License\n\nHtml2PDF for Laravel is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnahidulhasan%2Flaravel-pdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnahidulhasan%2Flaravel-pdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnahidulhasan%2Flaravel-pdf/lists"}