{"id":13606814,"url":"https://github.com/LukeTowers/oc-snappypdf-plugin","last_synced_at":"2025-04-12T11:30:48.332Z","repository":{"id":56134906,"uuid":"88534881","full_name":"LukeTowers/oc-snappypdf-plugin","owner":"LukeTowers","description":"SnappyPDF integration for OctoberCMS","archived":false,"fork":false,"pushed_at":"2022-06-21T14:56:22.000Z","size":26,"stargazers_count":11,"open_issues_count":2,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-02T03:00:30.999Z","etag":null,"topics":["barryvdh","laravel","octobercms","pdf","plugin","wkhtmltopdf"],"latest_commit_sha":null,"homepage":null,"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/LukeTowers.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}},"created_at":"2017-04-17T17:57:13.000Z","updated_at":"2024-02-21T01:30:50.000Z","dependencies_parsed_at":"2022-08-15T13:20:51.476Z","dependency_job_id":null,"html_url":"https://github.com/LukeTowers/oc-snappypdf-plugin","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LukeTowers%2Foc-snappypdf-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LukeTowers%2Foc-snappypdf-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LukeTowers%2Foc-snappypdf-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LukeTowers%2Foc-snappypdf-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LukeTowers","download_url":"https://codeload.github.com/LukeTowers/oc-snappypdf-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248560044,"owners_count":21124582,"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":["barryvdh","laravel","octobercms","pdf","plugin","wkhtmltopdf"],"created_at":"2024-08-01T19:01:12.624Z","updated_at":"2025-04-12T11:30:48.059Z","avatar_url":"https://github.com/LukeTowers.png","language":"PHP","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# About\n\nOctober-fied wrapper around the [wkhtmltopdf and wkhtmltoimage](https://wkhtmltopdf.org/) conversion libraries provided through the [barryvdh/laravel-snappy](https://github.com/barryvdh/laravel-snappy) package.\n\n# Installation\n\nTo install from the [Marketplace](https://octobercms.com/plugin/luketowers-snappypdf), click on the \"Add to Project\" button and then select the project you wish to add it to before updating the project to pull in the plugin.\n\nTo install from the backend, go to **Settings -\u003e Updates \u0026 Plugins -\u003e Install Plugins** and then search for `LukeTowers.SnappyPDF`.\n\nTo install from [the repository](https://github.com/luketowers/oc-snappypdf-plugin), clone it into **plugins/luketowers/snappypdf** and then run `composer update` from your project root in order to pull in the dependencies.\n\nTo install it with Composer, run `composer require luketowers/oc-snappypdf-plugin` from your project root.\n\n\u003e **NOTE:** On some Linux systems you may need to install the following dependencies (generally when the process fails with \"The exit status code 127 says something went wrong\"). Pulled from https://github.com/barryvdh/laravel-snappy/issues/68.\n\n```bash\nsudo apt-get install -y \\\nlibxrender1 \\\nlibfontconfig1 \\\nlibx11-dev \\\nlibjpeg62 \\\nlibxtst6\n```\n\nIf you get \"The exit status code 1 says something went wrong\" you may need to install the following dependencies. Pulled from https://github.com/wkhtmltopdf/wkhtmltopdf/issues/3001#issuecomment-309673453\n\n```bash\nsudo apt-get install -y \\\nlibssl1.0-dev\n```\n\u003e **NOTE:** You might not be able to install `libssl1.0-dev` in Homestead, make sure you run `sudo apt-get update` first.\n\n# Configuration\n\nThe main configuration values that you may wish to change would be the paths to the executable binaries for `wkhtmltopdf` and `wkhtmltoimage`. These binaries are pulled into **plugins/luketowers/snappypdf/vendor/bin** by default (when installing from the marketplace) and the default configuration reflects this. Also supported by default is installing by cloning the [repository](https://github.com/luketowers/oc-snappypdf-plugin) and loading the dependencies with `composer update` (where the binaries will be located in your project's **vendor/bin**).\n\nIf you need to change the path used to locate those binaries, then you have a few options. If you are already using [`.env` files for environment level configuration](http://octobercms.com/docs/setup/configuration#environment-config-extended) then you can simply add `SNAPPY_PDF_BINARY` and `SNAPPY_IMAGE_BINARY` with their respective paths to your `.env` file and call it a day.\n\nIf you are not using `.env` files, or you need to change a configuration value other than the binary paths; then you can override this plugin's configuration and change the necessary values by copying **config/config.php** from the plugin into your project's **config/luketowers/snappypdf/config.php** file [(as specified in the OctoberCMS docs)](http://octobercms.com/docs/plugin/settings#file-configuration).\n\n# Usage\n\nWhen using this plugin, it is highly recommended that you [add a dependency on it](http://octobercms.com/docs/plugin/registration#dependency-definitions) to the plugin you are using it from.\n\nIn order to use the libraries provided by this plugin (`SnappyPDF` and `SnappyImage`), simply import them with `use` statements at the top of your PHP files.\n\n### Stream PDF to browser\n\nThe example below will render a record from a controller and stream it to the browser for downloading or viewing.\n\n```php\n\u003c?php namespace MyVendor\\MyPlugin\\Controllers;\n\nuse File;\nuse Twig;\nuse Response;\nuse SnappyPDF;\nuse Backend\\Classes\\Controller;\n\nuse MyVendor\\MyPlugin\\Models\\Example as ExampleModel;\n\nclass Examples extends Controller\n{\n    public function download($id)\n    {\n        // Load the example record\n        $example = ExampleModel::find($id);\n\n        // Load the template\n        $template = File::get(plugins_path('myvendor/myplugin/views/example-record-template.htm'));\n\n        // Render the template\n        $renderedHtml = Twig::parse($template, [\n            'example' =\u003e $example,\n        ]);\n\n        // Render as a PDF\n        $pdf = SnappyPDF::loadHTML($renderedHtml)\n            -\u003esetOption('margin-top', 0)\n            -\u003esetOption('margin-bottom', 0)\n            -\u003esetOption('margin-left', 0)\n            -\u003esetOption('margin-right', 0)\n            -\u003esetPaper('letter')\n            -\u003eoutput();\n\n        return Response::make($pdf, 200, [\n            'Content-Type'        =\u003e 'application/pdf',\n            'Content-Disposition' =\u003e \"filename={$example-\u003ename}.pdf\",\n        ]);\n    }\n}\n```\n\n### Return a PDF to the AJAX framework for downloading\n\n```\n\u003c?php namespace MyVendor\\MyPlugin\\Controllers;\n\nuse File;\nuse Twig;\nuse Backend;\nuse Response;\nuse SnappyPDF;\nuse Backend\\Classes\\Controller;\n\nuse MyVendor\\MyPlugin\\Models\\Example as ExampleModel;\n\nclass Examples extends Controller\n{\n    public function onDownloadPDF()\n    {\n        $recordId = input('recordId');\n        return Backend::redirect(\"myvendor/myplugin/examples/download/$recordId\");\n    }\n    \n    public function download($id)\n    {\n        // Load the example record\n        $example = ExampleModel::find($id);\n\n        // Load the template\n        $template = File::get(plugins_path('myvendor/myplugin/views/example-record-template.htm'));\n\n        // Render the template\n        $renderedHtml = Twig::parse($template, [\n            'example' =\u003e $example,\n        ]);\n\n        // Render as a PDF\n        $pdf = SnappyPDF::loadHTML($renderedHtml)-\u003eoutput();\n\n        return Response::make($pdf, 200, [\n            'Content-Type'        =\u003e 'application/pdf',\n            'Content-Transfer-Encoding' =\u003e 'binary',\n            'Content-Disposition' =\u003e \"attachment; filename=\\\"{$example-\u003ename}.pdf\\\"\",\n        ]);\n    }\n}\n```\n\n\nMore information on utilizing the libraries is available at the [barryvdh/laravel-snappy repository](https://github.com/barryvdh/laravel-snappy#usage) and the [wkhtmltopdf manual](http://wkhtmltopdf.org/usage/wkhtmltopdf.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLukeTowers%2Foc-snappypdf-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLukeTowers%2Foc-snappypdf-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLukeTowers%2Foc-snappypdf-plugin/lists"}