PDF Generator with Laravel Framework?


I need to make snappy generate reports from BD data. But for this I needed examples of using snappy , in the documentation of github you even have an example, but that example did not help me. I needed an example of how to use Snappy with controller , views and rotas . Can someone help me, please?

@@ Edit

It does not have to be exactly that, it's what I saw in Laracasts which was the best PDF generator. I'll take a look at the dompdf documentation. Anyway, if I use the dompdf would you have a sample code like I said above? Thank you in advance

asked by anonymous 06.03.2017 / 19:04

1 answer


Minimum example:

Package installation barryvdh / laravel-dompdf


composer require barryvdh/laravel-dompdf

After the installation is complete, enter the app/config.php file and add the following settings:

'providers' => [ 


'aliases' => [
    'PDF' => Barryvdh\DomPDF\Facade::class,

go back to the command line and type:


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

to publish the settings in the config folder to the dompdf.php file.

There is a folder in the installation package that should be copied manually to the storage folder of , this folder contains the font files used by this package for generating reports in PDF and the path is vendor\dompdf\dompdf\lib , which looks like this.





Route::get('/viewpdf','[email protected]');


<!DOCTYPEhtml><htmllang="{{ config('app.locale') }}">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Fonts -->
    <link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
    <!-- Styles -->
        html, body {
            background-color: #fff;
            color: #636b6f;
            font-family: 'Raleway', sans-serif;
            font-weight: 100;
            height: 100vh;
            margin: 0;

        .full-height {
            height: 100vh;

        .flex-center {
            align-items: center;
            display: flex;
            justify-content: center;

        .position-ref {
            position: relative;

        .top-right {
            position: absolute;
            right: 10px;
            top: 18px;

        .content {
            text-align: center;

        .title {
            font-size: 84px;

        .links > a {
            color: #636b6f;
            padding: 0 25px;
            font-size: 12px;
            font-weight: 600;
            letter-spacing: .1rem;
            text-decoration: none;
            text-transform: uppercase;

        .m-b-md {
            margin-bottom: 30px;
<div class="flex-center position-ref full-height">
            @foreach($model as $item)

Having the output:


06.03.2017 / 20:58