KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

PhantomJS Issue #3168

Open Charlie May opened this topic on on Oct 10, 2023 - 4 comments

Charlie May commented on Oct 10, 2023

Hello, We hare experiencing an issue using the export on Linux but works fine on my Windows Dev computer.

OS: Ubuntu 22.04 PHP Version: 8.1

Running ./phantomjs --version I get this error

Auto configuration failed
140098268257920:error:25066067:DSO support routines:DLFCN_LOAD:could not load the shared library:dso_dlfcn.c:185:filename(libssl_conf.so): libssl_conf.so: cannot open shared object file: No such file or directory
140098268257920:error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244:
140098268257920:error:0E07506E:configuration file routines:MODULE_LOAD_DSO:error loading dso:conf_mod.c:285:module=ssl_conf, path=ssl_conf
140098268257920:error:0E076071:configuration file routines:MODULE_RUN:unknown module name:conf_mod.c:222:module=ssl_conf

This error can be resolved by running:

OPENSSL_CONF=/etc/ssl ./phantomjs --version

It responds with 2.1.1

When I run the export from Laravel I get "Could not execute phantomJS" I modified the Handler.php for export like such.

$command = "OPENSSL_CONF=/etc/ssl " .  $this->phantomjs . " --ignore-ssl-errors=true $script $source $output $params";

And the export downloads, however it throws an error saying something about the content needs to be string.

The file can be viewed in adobe reader. but it doesn't obtain the .pdf extension nor does it look the same as when I download it from the windows dev box.

This is not related to file names being uppercase lowercase. That issue was resolved already in a previous post.

Sebastian Morales commented on Oct 10, 2023

Would you mind posting your export's php code? With Koolreport Export you don't need to use Laravel response or any other method, just execute $report->run()->export(...)->pdf(...)->toBrowser(...) in the export route is enough.

Charlie May commented on Oct 10, 2023

Again this works perfectly fine within my Windows Dev Server without the need of adding OPENSSL_CONF=/etc/ssl to the command.

On Windows: PDF Export works with .pdf extension without modification to the vendor/koolreport/export/Handler.php file.

On Linux: phantomjs fails to execute without modify the Handler.php file for export to include the OPENSSL_CONF setting.

When that is appended on the command the other error above is listed where you see the response from symphony.

ExportsController.php

public function compliance()
    {
        $report = new \App\Reports\tenant\compliance\ComplianceReportExport;
        return $report->run()->export()->settings([
            "useLocalTempFolder" => true,
            "autoDeleteTempFile" => true,
        ])->pdf([
            "format" => "A4",
            "orientation" => "portrait",
            "zoom" => -3
        ])->toBrowser(now()->timezone('America/Los_Angeles')->format('Ymd') . 'regional_compliance');
    }

CompliaceReportExport.php

<?php

namespace App\Reports\tenant\compliance;

class ComplianceReportExport extends \koolreport\KoolReport
{
    use \koolreport\laravel\Friendship;
    use \koolreport\export\Exportable;
    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;
    use \koolreport\export\Exportable;

    function settings(): array
    {
        return [
            "dataSources" => [
                "elo" => [
                    "class" => '\koolreport\laravel\Eloquent',
                ]
            ]
        ];
    }

    protected function defaultParamValues(): array
    {
        return [
            "dateRange" => [now()->subDay()->timezone('America/Los_Angeles'), now()->addDays(90)->timezone('America/Los_Angeles')],
            "dateRangeStart" => null,
            "dateRangeEnd" => null,
        ];
    }

    protected function bindParamsToInputs(): array
    {
        return [
            "dateRange",
            "dateRangeStart",
            "dateRangeEnd"
        ];
    }

    function setup(): void
    {
        if (isset($this->params['dateRangeStart']) && isset($this->params['dateRangeEnd'])) {
            $dateRange = [$this->params['dateRangeStart'], $this->params['dateRangeEnd']];
        } else {
            $dateRange = $this->params['dateRange'];
        }

        $this->src("elo")->query(
            \App\Models\Tenant\License::select('companies.name as Company Name', 'regions.name as Region Name', 'communities.name as Community Name', 'number as License Number', 'expiration_date as Expiration Date')
                ->join('communities', 'communities.id', '=', 'licenses.community_id')
                ->leftJoin('companies', 'companies.id', '=', 'communities.company_id')
                ->leftJoin('regions', 'regions.id', '=', 'communities.region_id')
                ->whereBetween('expiration_date', $dateRange)
                ->when(auth()->user()->communities()->count(), function ($query) {
                    return $query->whereIn('community_id', auth()->user()->communities()->pluck('community_id')->toArray());
                })
                ->when(auth()->user()->companies()->count(), function ($query) {
                    return $query->whereIn('communities.company_id', auth()->user()->companies()->pluck('company_id')->toArray());
                })
                ->when(auth()->user()->regions()->count(), function ($query) {
                    return $query->whereIn('communities.region_id', auth()->user()->regions()->pluck('region_id')->toArray());
                })
                ->orderBy('expiration_date', 'asc')
        )
            ->pipe($this->dataStore("license"));

        $this->src("elo")->query(
            \App\Models\Tenant\Permit::select('companies.name as Company Name', 'regions.name as Region Name', 'communities.name as Community Name', 'number as Permit Number', 'type as Permit Type', 'issuing_agency as Issuing Agency', 'expiration_date as Expiration Date')
                ->join('communities', 'communities.id', '=', 'permits.community_id')
                ->leftJoin('companies', 'companies.id', '=', 'communities.company_id')
                ->leftJoin('regions', 'regions.id', '=', 'communities.region_id')
                ->whereBetween('expiration_date', $dateRange)
                ->when(auth()->user()->communities()->count(), function ($query) {
                    return $query->whereIn('community_id', auth()->user()->communities()->pluck('community_id')->toArray());
                })
                ->when(auth()->user()->companies()->count(), function ($query) {
                    return $query->whereIn('communities.company_id', auth()->user()->companies()->pluck('company_id')->toArray());
                })
                ->when(auth()->user()->regions()->count(), function ($query) {
                    return $query->whereIn('communities.region_id', auth()->user()->regions()->pluck('region_id')->toArray());
                })
                ->orderBy('expiration_date', 'asc')
        )
            ->pipe($this->dataStore("permit"));

        $this->src("elo")->query(
            \App\Models\Tenant\Clia::select('companies.name as Company Name', 'regions.name as Region Name', 'communities.name as Community Name', 'number as CLIA Number', 'type as CLIA Type', 'expiration_date as Expiration Date')
                ->join('communities', 'communities.id', '=', 'clias.community_id')
                ->leftJoin('companies', 'companies.id', '=', 'communities.company_id')
                ->leftJoin('regions', 'regions.id', '=', 'communities.region_id')
                ->whereBetween('expiration_date', $dateRange)
                ->when(auth()->user()->communities()->count(), function ($query) {
                    return $query->whereIn('community_id', auth()->user()->communities()->pluck('community_id')->toArray());
                })
                ->when(auth()->user()->companies()->count(), function ($query) {
                    return $query->whereIn('communities.company_id', auth()->user()->companies()->pluck('company_id')->toArray());
                })
                ->when(auth()->user()->regions()->count(), function ($query) {
                    return $query->whereIn('communities.region_id', auth()->user()->regions()->pluck('region_id')->toArray());
                })
                ->orderBy('expiration_date', 'asc')
        )
            ->pipe($this->dataStore("clia"));

        $this->src("elo")->query(
            \App\Models\Tenant\Penalty::select('companies.name as Company Name', 'regions.name as Region Name', 'communities.name as Community Name', 'agency_reports.description as Agency Report Description', 'penalties.poc_due as POC Due Date', 'penalties.fine_due_date as Fine Due Date')
                ->join('agency_reports', 'agency_reports.id', '=', 'penalties.agency_report_id')
                ->join('communities', 'communities.id', '=', 'agency_reports.community_id')
                ->leftJoin('companies', 'companies.id', '=', 'communities.company_id')
                ->leftJoin('regions', 'regions.id', '=', 'communities.region_id')
                ->where(function ($query) use ($dateRange) {
                    $query->whereBetween('penalties.poc_due', $dateRange)->orWhereBetween('penalties.fine_due_date', $dateRange);
                })
                ->when(auth()->user()->communities()->count(), function ($query) {
                    return $query->whereIn('agency_reports.community_id', auth()->user()->communities()->pluck('community_id')->toArray());
                })
                ->when(auth()->user()->companies()->count(), function ($query) {
                    return $query->whereIn('communities.company_id', auth()->user()->companies()->pluck('company_id')->toArray());
                })
                ->when(auth()->user()->regions()->count(), function ($query) {
                    return $query->whereIn('communities.region_id', auth()->user()->regions()->pluck('region_id')->toArray());
                })
                ->where('penalties.status', 1)
                ->orderBy('penalties.poc_due', 'asc')
        )
            ->pipe($this->dataStore("penalty"));
    }
}

ComplianceReportExport.view.php

<html lang="en">

<head>
    <title></title>
</head>

<style>
    .table-header {
        background-color: #f2f2f2;
        border: 1px solid #ddd;
        font-weight: bold;
        text-align: center;
        font-size: 12pt;
        padding: 5px 0;
    }

    .table-data {
        padding: 5px;
        font-weight: normal;
        text-align: left;
        font-size: 10pt;
    }

    .table-row {
        border: 1px solid #ddd;
    }

    .table-row:nth-child(even) {
        background-color: #f2f2f2;
    }

    .table-row:nth-child(odd) {
        background-color: #ffffff;
    }

    .table {
        border-collapse: collapse;
        width: 100%;
    }
</style>

<body style="background-color: #ffffff; margin: 10px 20px 10px 20px;">
    <div class="report-content">
        <div style="text-align: center">
            <h1>Compliance Report</h1>
            <p class="lead">
                Date Range: <?php echo Carbon\Carbon::parse($this->params["dateRangeStart"])->format('m-d-Y') ?>
                to <?php echo Carbon\Carbon::parse($this->params["dateRangeEnd"])->format('m-d-Y') ?>
            </p>
        </div>
        <div>
            <h2>Licenses</h2>
            <?php
            \koolreport\widgets\koolphp\Table::create([
                "dataSource" => $this->dataStore("license"),
                "emptyValue" => "",
                'cssClass' =>
                [
                    'table' => 'table',
                    'tr' => 'table-row',
                    'th' => 'table-header',
                    'td' => 'table-data'
                ],
            ]);
            ?>

            <div class="page-break"></div>
            <h2>Permits</h2>
            <?php
            \koolreport\widgets\koolphp\Table::create([
                "dataSource" => $this->dataStore("permit"),
                "emptyValue" => "",
                'cssClass' =>
                [
                    'table' => 'table',
                    'tr' => 'table-row',
                    'th' => 'table-header',
                    'td' => 'table-data'
                ],
            ]);
            ?>

            <div class="page-break"></div>
            <h2>CLIAs</h2>
            <?php
            \koolreport\widgets\koolphp\Table::create([
                "dataSource" => $this->dataStore("clia"),
                "emptyValue" => "",
                'cssClass' =>
                [
                    'table' => 'table',
                    'tr' => 'table-row',
                    'th' => 'table-header',
                    'td' => 'table-data'
                ],
            ]);
            ?>

            <div class="page-break"></div>
            <h2>Defficiencies & Penalties</h2>
            <?php
            \koolreport\widgets\koolphp\Table::create([
                "dataSource" => $this->dataStore("penalty"),
                "emptyValue" => "",
                'cssClass' =>
                [
                    'table' => 'table',
                    'tr' => 'table-row',
                    'th' => 'table-header',
                    'td' => 'table-data'
                ],
            ]);
            ?>
        </div>
    </div>
</body>

</html>
Charlie May commented on Oct 13, 2023

Any update on this case?

Sebastian Morales commented on Oct 16, 2023

Sorry for the delay. Would you pls test changing ->toBrowser(...) method to ->saveAs($pdfFileOnServer) one and check if the $pdfFileOnServer file is correct?

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
bug

Export