How to Use Laravel Snappy with Laragon

laravel 8

Laravel Snappy is a PHP package for Snappy; which allow you to create PDF or image file from a URL or a HTML page. To use Laravel Snappy with Laragon, you need a specific setup for it to work.

At the time of writing, Laravel 8 is the latest version. For this tutorial, I’m using Laragon 4.0.16 with PHP v7.4.14, and Apache 2.4. Without further a due, let start this tutorial.

Step 1

In order for Laravel Snappy to work, you need to install wkhtmltopdf. Go to wkhtmltopdf and download the installer for your Windows. Install wkhtmltopdf using the installer afterward.

Step 2

Install Laravel Snappy package to your Laravel project using composer.

composer require barryvdh/laravel-snappy

Step 3

Publish Laravel Snappy configuration file using artisan command.

php artisan vendor:publish --provider="Barryvdh\Snappy\ServiceProvider"

You can check the config file and put customize it accordingly.

Step 4

Add new variables for WKHTML_PDF_BINARY and WKHTML_IMAGE_BINARY in your .env file. The value for these variables should be map to your wkhtmltopdf exe file location. For example:

WKHTML_PDF_BINARY="D:\\wkhtmltopdf\\bin\\wkhtmltopdf.exe"
WKHTML_IMAGE_BINARY="D:\\wkhtmltopdf\\bin\\wkhtmltoimage.exe"

That’s all. Now you are ready to use Laravel Snappy in Laragon to develop further your Laravel project.