{"id":13588944,"url":"https://github.com/niklasravnsborg/laravel-pdf","last_synced_at":"2025-04-08T07:31:32.879Z","repository":{"id":7816729,"uuid":"56491365","full_name":"niklasravnsborg/laravel-pdf","owner":"niklasravnsborg","description":"📄 Laravel PDF","archived":true,"fork":false,"pushed_at":"2023-08-22T12:16:36.000Z","size":105,"stargazers_count":707,"open_issues_count":44,"forks_count":208,"subscribers_count":24,"default_branch":"main","last_synced_at":"2024-05-18T16:46:11.260Z","etag":null,"topics":["laravel","mpdf","pdf-generation"],"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/niklasravnsborg.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,"governance":null}},"created_at":"2016-04-18T08:41:25.000Z","updated_at":"2024-05-03T10:26:51.000Z","dependencies_parsed_at":"2022-07-14T07:20:32.024Z","dependency_job_id":"e3466fad-4fa8-4a1f-8f68-1ed060c6e9ec","html_url":"https://github.com/niklasravnsborg/laravel-pdf","commit_stats":{"total_commits":53,"total_committers":12,"mean_commits":4.416666666666667,"dds":"0.37735849056603776","last_synced_commit":"a5f5c22dd5e10d8f536102cec01c21282e18ebae"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasravnsborg%2Flaravel-pdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasravnsborg%2Flaravel-pdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasravnsborg%2Flaravel-pdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasravnsborg%2Flaravel-pdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/niklasravnsborg","download_url":"https://codeload.github.com/niklasravnsborg/laravel-pdf/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247796147,"owners_count":20997521,"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":["laravel","mpdf","pdf-generation"],"created_at":"2024-08-01T16:00:14.989Z","updated_at":"2025-04-08T07:31:32.560Z","avatar_url":"https://github.com/niklasravnsborg.png","language":"PHP","funding_links":[],"categories":["PHP","Add-ons/Components"],"sub_categories":["Misc/Multi-language"],"readme":"\u003e [!WARNING]  \n\u003e niklasravnsborg/laravel-pdf is not maintained! This repository has been deprecated and archived on 2023-08-22.\n\u003e Look at https://github.com/misterspelik/laravel-pdf for a potential alternative.\n\n# Laravel PDF: mPDF wrapper for Laravel 5\n\n\u003e Easily generate PDF documents from HTML right inside of Laravel using this mPDF wrapper.\n\n\n## Installation\n\nRequire this package in your `composer.json` or install it by running:\n\n```\ncomposer require niklasravnsborg/laravel-pdf\n```\n\n\u003e Note: This package supports auto-discovery features of Laravel 5.5+, You only need to manually add the service provider and alias if working on Laravel version lower then 5.5\n\nTo start using Laravel, add the Service Provider and the Facade to your `config/app.php`:\n\n```php\n'providers' =\u003e [\n\t// ...\n\tniklasravnsborg\\LaravelPdf\\PdfServiceProvider::class\n]\n```\n\n```php\n'aliases' =\u003e [\n\t// ...\n\t'PDF' =\u003e niklasravnsborg\\LaravelPdf\\Facades\\Pdf::class\n]\n```\n\nNow, you should publish package's config file to your config directory by using following command:\n\n```\nphp artisan vendor:publish\n```\n\n## Basic Usage\n\nTo use Laravel PDF add something like this to one of your controllers. You can pass data to a view in `/resources/views`.\n\n```php\nuse PDF;\n\nfunction generate_pdf() {\n\t$data = [\n\t\t'foo' =\u003e 'bar'\n\t];\n\t$pdf = PDF::loadView('pdf.document', $data);\n\treturn $pdf-\u003estream('document.pdf');\n}\n```\n\n## Other methods\n\nIt is also possible to use the following methods on the `pdf` object:\n\n`output()`: Outputs the PDF as a string.  \n`save($filename)`: Save the PDF to a file  \n`download($filename)`: Make the PDF downloadable by the user.  \n`stream($filename)`: Return a response with the PDF to show in the browser.\n\n## Config\n\nIf you have published config file, you can change the default settings in `config/pdf.php` file:\n\n```php\nreturn [\n\t'format'           =\u003e 'A4', // See https://mpdf.github.io/paging/page-size-orientation.html\n\t'author'           =\u003e 'John Doe',\n\t'subject'          =\u003e 'This Document will explain the whole universe.',\n\t'keywords'         =\u003e 'PDF, Laravel, Package, Peace', // Separate values with comma\n\t'creator'          =\u003e 'Laravel Pdf',\n\t'display_mode'     =\u003e 'fullpage'\n];\n```\n\nTo override this configuration on a per-file basis use the fourth parameter of the initializing call like this:\n\n```php\nPDF::loadView('pdf', $data, [], [\n  'format' =\u003e 'A5-L'\n])-\u003esave($pdfFilePath);\n```\n\nYou can use a callback with the key 'instanceConfigurator' to access mpdf functions:\n```php\n$config = ['instanceConfigurator' =\u003e function($mpdf) {\n    $mpdf-\u003eSetImportUse();\n    $mpdf-\u003eSetDocTemplate(/path/example.pdf, true);\n}]\n \nPDF::loadView('pdf', $data, [], $config)-\u003esave($pdfFilePath);\n```\n\n## Headers and Footers\n\nIf you want to have headers and footers that appear on every page, add them to your `\u003cbody\u003e` tag like this:\n\n```html\n\u003chtmlpageheader name=\"page-header\"\u003e\n\tYour Header Content\n\u003c/htmlpageheader\u003e\n\n\u003chtmlpagefooter name=\"page-footer\"\u003e\n\tYour Footer Content\n\u003c/htmlpagefooter\u003e\n```\n\nNow you just need to define them with the name attribute in your CSS:\n\n```css\n@page {\n\theader: page-header;\n\tfooter: page-footer;\n}\n```\n\nInside of headers and footers `{PAGENO}` can be used to display the page number.\n\n## Included Fonts\n\nBy default you can use all the fonts [shipped with mPDF](https://mpdf.github.io/fonts-languages/available-fonts-v6.html).\n\n## Custom Fonts\n\nYou can use your own fonts in the generated PDFs. The TTF files have to be located in one folder, e.g. `/resources/fonts/`. Add this to your configuration file (`/config/pdf.php`):\n\n```php\nreturn [\n\t// ...\n\t'font_path' =\u003e base_path('resources/fonts/'),\n\t'font_data' =\u003e [\n\t\t'examplefont' =\u003e [\n\t\t\t'R'  =\u003e 'ExampleFont-Regular.ttf',    // regular font\n\t\t\t'B'  =\u003e 'ExampleFont-Bold.ttf',       // optional: bold font\n\t\t\t'I'  =\u003e 'ExampleFont-Italic.ttf',     // optional: italic font\n\t\t\t'BI' =\u003e 'ExampleFont-Bold-Italic.ttf' // optional: bold-italic font\n\t\t\t//'useOTL' =\u003e 0xFF,    // required for complicated langs like Persian, Arabic and Chinese\n\t\t\t//'useKashida' =\u003e 75,  // required for complicated langs like Persian, Arabic and Chinese\n\t\t]\n\t\t// ...add as many as you want.\n\t]\n\t// ...\n];\n```\n\n*Note*: If you are using `laravel-pdf` for producing PDF documents in a complicated language (like Persian, Arabic or Chinese) you should have `useOTL` and `useKashida` indexes in your custom font definition array. If you do not use these indexes, your characters will be shown dispatched and incorrectly in the produced PDF.\n\nNow you can use the font in CSS:\n\n```css\nbody {\n\tfont-family: 'examplefont', sans-serif;\n}\n```\n\n## Set Protection\n\nTo set protection, you just call the `SetProtection()` method and pass an array with permissions, an user password and an owner password.\n\nThe passwords are optional.\n\nThere are a fews permissions: `'copy'`, `'print'`, `'modify'`, `'annot-forms'`, `'fill-forms'`, `'extract'`, `'assemble'`, `'print-highres'`.\n\n```php\nuse PDF;\n\nfunction generate_pdf() {\n\t$data = [\n\t\t'foo' =\u003e 'bar'\n\t];\n\t$pdf = PDF::loadView('pdf.document', $data);\n\t$pdf-\u003eSetProtection(['copy', 'print'], '', 'pass');\n\treturn $pdf-\u003estream('document.pdf');\n}\n```\n\nFind more information to `SetProtection()` here: https://mpdf.github.io/reference/mpdf-functions/setprotection.html\n\n## Testing\n\nTo use the testing suite, you need some extensions and binaries for your local PHP. On macOS, you can install them like this:\n\n```\nbrew install imagemagick ghostscript\npecl install imagick\n```\n\n## License\n\nLaravel PDF 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%2Fniklasravnsborg%2Flaravel-pdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fniklasravnsborg%2Flaravel-pdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniklasravnsborg%2Flaravel-pdf/lists"}