Dani Banai
Dani Banai

Reputation: 1140

Laravel 5.2 - PHPExcel_Writer_Exception: Unable to load PDF Rendering library in

I have a EC2 instance with ubuntu 14.04, Apache2, php 7.2, Laravel 5.2.

When a user hit this function:

    public function show(Request $request, $id)
{
    $type = $id; // 'pdf' / 'xls'
    $data = $this->getConversionsByDate();
    $data = $this->parseData($data['conversions'],$type);

    return Excel::create('project_conversions_data_'.Carbon::now()->toDateTimeString(), function($excel) use ($data) {
        $excel->sheet('mySheet', function($sheet) use ($data){
            $sheet->fromArray($data);
        });
    })->download($type);
}

When type = 'xls' -> it's working fine. But, When type = 'pdf' I have this new error:

PHPExcel_Writer_Exception: Unable to load PDF Rendering library in /var/www/html/project/releases/20190108072816/vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/PDF/DomPDF.php:8

This is my composer.json file:

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.2.*",
    "laravelcollective/html": "5.2.*",
    "jenssegers/agent": "2.3.*",
    "doctrine/dbal": "v2.5.5",
    "guzzlehttp/guzzle": "~6.0",
    "laravel/cashier": "~6.0",
    "spatie/laravel-backup":"^3.0.0",
    "maatwebsite/excel": "~2.1.0",
    "rap2hpoutre/laravel-log-viewer":"0.8.0",
    "arcanedev/log-viewer": "4.2.*",
    "tymon/jwt-auth": "0.5.*",
    "aws/aws-sdk-php-laravel": "3.1.0",
    "league/flysystem-aws-s3-v3": "~1.0.0",
    "maknz/slack-laravel": "^1.0"
},
"require-dev": {
    "fzaninotto/faker": "~1.4",
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "~4.0",
    "symfony/css-selector": "2.8.*|3.0.*",
    "symfony/dom-crawler": "2.8.*|3.0.*"
},
"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/"
    },
    "files": [
       "app/helpers.php"
    ]
},
"autoload-dev": {
    "classmap": [
        "tests/TestCase.php"
    ]
},
"scripts": {
    "post-root-package-install": [
        "php -r \"copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ],
    "post-install-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postInstall"
    ],
    "post-update-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postUpdate"
    ]
},
"config": {
    "preferred-install": "dist"
}

}

Please Help!!!

Upvotes: 1

Views: 1552

Answers (2)

Dani Banai
Dani Banai

Reputation: 1140

This was the solution for me:

composer require tecnickcom/tcpdf

Go to config/excel.php and change this:

'driver'  => 'DomPDF',

to

'driver'  => 'tcPDF',

In the same file, change this:

            'tcPDF'  => array(
                'path' => base_path('vendor/tecnick.com/tcpdf/')
            ),

To:

            'tcPDF'  => array(
                'path' => base_path('vendor/tecnickcom/tcpdf/')
            ),

And it work :)

Upvotes: 2

Buwaneka Kalansuriya
Buwaneka Kalansuriya

Reputation: 146

This is what I found with a quick look at the documentation. Please check if the following packages are there in your package.json

Export to PDF To export files to pdf, you will have to include "dompdf/dompdf": "~0.6.1", "mpdf/mpdf": "~6.1" or "tecnick.com/tcpdf": "~6.0.0" in your composer.json and change the export.pdf.driver config setting accordingly.

Upvotes: 0

Related Questions