{"id":17473888,"url":"https://github.com/gocanto/laravel-simple-pdf","last_synced_at":"2025-08-10T03:34:56.247Z","repository":{"id":55503720,"uuid":"191315112","full_name":"gocanto/laravel-simple-pdf","owner":"gocanto","description":"Simple laravel PDF generator.","archived":false,"fork":false,"pushed_at":"2020-12-26T04:22:29.000Z","size":30,"stargazers_count":22,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-22T10:39:11.174Z","etag":null,"topics":["generator","laravel","pdf","php"],"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/gocanto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-11T07:14:31.000Z","updated_at":"2023-04-02T03:53:50.000Z","dependencies_parsed_at":"2022-08-15T02:00:20.899Z","dependency_job_id":null,"html_url":"https://github.com/gocanto/laravel-simple-pdf","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":"gocanto/php-template","purl":"pkg:github/gocanto/laravel-simple-pdf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocanto%2Flaravel-simple-pdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocanto%2Flaravel-simple-pdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocanto%2Flaravel-simple-pdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocanto%2Flaravel-simple-pdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gocanto","download_url":"https://codeload.github.com/gocanto/laravel-simple-pdf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocanto%2Flaravel-simple-pdf/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269672058,"owners_count":24457112,"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-08-10T02:00:08.965Z","response_time":71,"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":["generator","laravel","pdf","php"],"created_at":"2024-10-18T18:07:36.183Z","updated_at":"2025-08-10T03:34:56.224Z","avatar_url":"https://github.com/gocanto.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## About it\n\n\u003ca href=\"https://packagist.org/packages/gocanto/laravel-simple-pdf\"\u003e\u003cimg src=\"https://img.shields.io/packagist/dt/gocanto/laravel-simple-pdf.svg?style=flat-square\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/gocanto/laravel-simple-pdf\"\u003e\u003cimg src=\"https://img.shields.io/github/release/gocanto/laravel-simple-pdf.svg?style=flat-square\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n\u003ca href=\"https://travis-ci.org/gocanto/laravel-simple-pdf\"\u003e\u003cimg src=\"https://img.shields.io/travis/gocanto/laravel-simple-pdf/master.svg?style=flat-square\" alt=\"Build status\"\u003e\u003c/a\u003e\n\nThis library is a minimalist on demand and `immutable PDF generator` for Laravel. It aims to keep a small friction once you need to generate a printable file using a intuitive public API.\n\nSimple PDF is shipped with a default template that you will be able to use to frame your next PDF files. You can see its layout [here](https://github.com/gocanto/laravel-simple-pdf/blob/master/resources/views/templates/default.blade.php)\n\n## Installation\n\nThis library uses [Composer](https://getcomposer.org) to manage its dependencies. So, before using it, make sure you have it installed in your machine. \nOnce you have done this, you will be able to pull this library in by typing the following command in your terminal.\n\n```\ncomposer require gocanto/laravel-simple-pdf\n```\n\n## Default template implementation\n\nUsing the default template is the easiest way to get started. Like so:\n\n```php\nuse Gocanto\\SimplePDF\\Builder;\nuse Gocanto\\SimplePDF\\TemplateContext;\n\nRoute::get('default-template', function (Builder $builder) {\n\n    $context = TemplateContext::make([\n        'title' =\u003e 'foo',\n        'name' =\u003e 'bar',\n        'content' =\u003e '\u003ch1\u003eSome amazing content!\u003c/h1\u003e',\n    ]);\n\n    $builder-\u003emake($context);\n\n    return $builder-\u003erender();\n});\n```\n\n***What's going on here ?***\n\n- First of all, we imported the `Builder` and the `Template Context` objects; you can think about them as the manager to generate your PDF files. For instance, the `Builder` \nis the one on charge of creating the `Stream File` we will be rendering on demand while the another one holds the data to be display within the default template.\n\n- Second of all,  we created the `TemplateContext` object with the desired data to be shown in our PDF file. The context object is a simple value object that holds some handy methods \nto manipulate the given array within our blade files. [See more](https://github.com/gocanto/laravel-simple-pdf/blob/master/src/TemplateContext.php)  \n\n- Lastly, we invoke the `make` method passing in our context object and finish by returning with the `render` functionality. \n\n## Custom template implementation\n\nThis implementation is done out of the same API, but it has a bit of configuration on the top. Like so: \n\n```php\n\nuse Gocanto\\SimplePDF\\Builder;\nuse Gocanto\\SimplePDF\\TemplateContext;\n\nRoute::get('custom-template', function (Builder $builder) {\n\n    $context = TemplateContext::make([\n        'title' =\u003e 'foo',\n        'name' =\u003e 'bar',\n        'content' =\u003e '\u003ch1\u003eSome amazing content!\u003c/h1\u003e',\n    ]);\n\n    $builder-\u003eaddLocation(resource_path('views/home'));\n    $new = $builder-\u003ewithTemplate('home');\n    $new-\u003emake($context);\n\n    return $new-\u003erender();\n});\n```\n\nAs you can see, the first `three steps` are the same as the default implementation, so there is no need to explain further on this regard. Now, we need to clarify the differences on its \nsetup.\n\n- First of all, we tell the builder about our templates root folder by invoking the `addLocation` method. This way, we will be able to have a views root folder to keep our different templates.\n\n- Second of all, we will register the custom templates by calling the `withTemplate` method. Please, do bear in account this is an immutable method, therefore, we will have a \nnew `Builder` instance as result.\n\n- Lastly, we will call the `make` and `render` method in the same way we did with the default template above.\n\n## Features\n\n- Multi templates ability.\n- The state is immutable, meaning all the withers as `withStream`, `withTemplate` and `withHeaders` methods will return a new instance of the `Builder`.\n- The exported stream is expose for custom manipulations, meaning you can pass a call back to the render method to manipulate the given stream before rendering time. Like so:\n```php\nuse Psr\\Http\\Message\\StreamInterface;\n\n$new-\u003erender(function (StreamInterface $stream) {\n    //do something amazing with the stream\n    echo $stream-\u003egetContents();\n});\n```\n\n## TO DO\n\n- [ ] (Gus) Allow rendered HTML or Blades files template as part of the `TemplateContext` content field.\n- [ ] (interested?) Allow more engines like twig.\n- [ ] (interested?) Make it framework agnostic.\n\n## Contributing\n\nPlease feel free to fork this package and contribute by submitting a pull request to enhance its functionality.\n\n## License\n\nThe MIT License (MIT). Please see [License File](https://github.com/gocanto/laravel-simple-pdf/blob/master/LICENSE.md) for more information.\n\n\n## How can I thank you?\nWhy not star the github repo and share the link for this repository on Twitter?\n\n\nDon't forget to [follow me on twitter](https://twitter.com/gocanto)!\n\nThanks!\n\nGustavo Ocanto.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgocanto%2Flaravel-simple-pdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgocanto%2Flaravel-simple-pdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgocanto%2Flaravel-simple-pdf/lists"}