KoolReport's Forum

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

CloudExport character encoding #1130

Open Ralf Föhring opened this topic on on Oct 16, 2019 - 17 comments

Ralf Föhring commented on Oct 16, 2019

Hi, this is how the € sign and other german characters get displayed in the pfd

David Winterburn commented on Oct 17, 2019

Hi Ralf,

Would you please send us your pdf view php file which contains german characters, in utf-8 if possible? Thanks!

Ralf Föhring commented on Oct 23, 2019

Hi David,

This is the only code related to pdf exporting

<?php
include "MyReport.php";
$report = new MyReport;
$report->run()->cloudExport("MyReport")
->chromeHeadlessio('.....')
->pdf(array(
    "format"=>"A4",
    "landscape"=>true,
    "printBackground"=>false,

))->toBrowser("Auftragspivot.pdf");
David Winterburn commented on Oct 23, 2019

Hi Ralf,

Please send us a sample of your data in csv or sql files which contains German characters to our email support@koolphp.net for us to test it for you. Thanks!

David Winterburn commented on Oct 23, 2019

By the way, please try adding this meta to the beginning of your page if your character encoding is of type utf-8:

<head>
  <meta charset="UTF-8">

Let us know the result. Thanks!

Ralf Föhring commented on Oct 23, 2019

I had the UTF-8 set in the run.example.php. I now try to use a custom pdf view. How can I make use of the PivotTable widget in a pdf view file ? This is what I have tried.

<?php
    use \koolreport\pivot\widgets\PivotTable;
?>
<meta charset="UTF-8">
<meta name="creator" content="John Doe">
<meta name="subject" content="subject1">
<meta name="title" content="title1">
<meta name="category" content="category1">

    
    <div>Sales PivotTable</div>
        <?php

    function translate( $v, $f ){

        switch ($v) {
            case 'sale_amount - sum': return 'Summe';
            case 'sale_amount - count': return 'Anzahl';
            case 'sale_amount - avg': return 'Durchschnitt';
            case 'price - avg': return 'Preis &Oslash';
            case 'quantity_amount - sum': return 'Menge';
            case 'factor - sum': return 'Faktor';
            case 'detail_id - count': return 'Positionen';
            case 'order_id': return 'Id';
            case 'order_id - distinctCount': return 'Aufträge';
            case 'year': return 'Jahr';
            case 'quarter': return 'Quartal';
            case 'month': return 'Monat';
            case 'day': return 'Tag';
            case 'from_location_text': return 'Von Standort';
            case 'to_location_text': return 'Nach Standort';
            case 'from_city': return 'Von Ort';
            case 'to_city': return 'Nach Ort';
            case 'article_text': return 'Artikel';
            case 'customer_text': return 'Kunde';
            case 'employee_text': return 'Mitarbeiter';
            case 'duration_hours - sum': return 'Dauer (Std.)';
            case 'duration_days - sum': return 'Dauer (Tage)';
        }
        $r = $v;
        if ($f === 'year')
            $r = 'Year ' . $v;
        $map = array(
            '' => '',
            '1' => 'Januar',
            '2' => 'Februar',
            '3' => 'März',
            '4' => 'April',
            '5' => 'Mai',
            '6' => 'Juni',
            '7' => 'Juli',
            '8' => 'August',
            '9' => 'September',
            '10' => 'Oktober',
            '11' => 'November',
            '12' => 'Dezember',
        );
        if ($f === 'month')
            $r = $map[$v];
        return $r;
    }
    PivotTable::create(array(
        "dataSource" => 'sales',
        // 'hideSubTotalRows' => true,
        // 'hideSubTotalColumns' => true,
        // 'hideGrandTotalRow' => true,
        // 'hideGrandTotalColumn' => true,
        "showDataHeaders" => true,
        'map' => array(
            'rowField' => function($rowField, $fieldInfo) {
                return translate( $rowField, '' );
            },
            'columnField' => function($colField, $fieldInfo) {
                return translate( $colField, '' );
            },
            'dataField' => function($dataField, $fieldInfo) {
                return translate( $dataField, '' );
            },
            'waitingField' => function($waitingField, $fieldInfo) {
                return translate( $waitingField, '' );
            },
            'dataHeader' => function($dataHeader, $headerInfo) {
                return translate( $dataHeader, '' );
            },
            'columnHeader' => function($colHeader, $headerInfo) {
                $v = $colHeader;
                if ($headerInfo['fieldName'] === 'month')
                    $v = translate($v, $headerInfo['fieldName']);
    
                return $v;
            },
        )));
    ?>
    </div>
</div>

David Winterburn commented on Oct 24, 2019

Hi Ralf,

For PivotTable in pdf view file, please set its datasource like this:

"dataSource" => $this->dataStore('sales'), //instead of "sales"

For the utf-8 problem, please add the charset="utf-8" meta tag to your pdf view file instead of run.example.php. Thanks!

Ralf Föhring commented on Dec 17, 2019

Thanks.

Now I get an empty page when I request the report from my online the server. But the report looks fine when I request it from my local environment.

From online environment:

From local environment:

Ralf Föhring commented on Dec 17, 2019

Also getting this error when cloud exporting:

David Winterburn commented on Dec 18, 2019

Hi Ralf,

If you replace PivotTable widget with some text, does cloud exporting work fine? Thanks!

Ralf Föhring commented on Dec 18, 2019

Hi, Yes, with a plain text it works fine. I am using the same cloud exporting on both local machine and online server.

Ralf Föhring commented on Dec 21, 2019

Do I need some specific server permissions?

David Winterburn commented on Jan 7, 2020

Hi Ralf,

If your local environment works fine with cloud export while the server one doesn't there could be some different in PHP setting between the two. Please try to put the following command to the beginning of your export code on your server:

<?php
// Turn off all error reporting
error_reporting(0);
?>

Let us know if it works. Thanks!

Ralf Föhring commented on Jan 8, 2020

Hi David,

I did a test by printing the word "location" several times and I suspect there is a formatting problem.

this is form my local

my local

and this is from the server

My code is the following: run.php

<?php
error_reporting(0);
require_once "MyReport.php";
$MyReport = new MyReport;
$MyReport->run()->render();
?>  

index.php

<?php 
error_reporting(0);
if(isset($_POST['exportExcel']) || isset($_POST['exportPdf']))
{
    include "export.php";
}
else
{
    include "../helpers/run.example.php";
}
?>

exportPdf.php

<?php
error_reporting(0);
include "MyReport.php";
$report = new MyReport;
$report->run()->cloudExport("MyReportPDF")
->chromeHeadlessio('6325cfa6ffaaf018a00f8f87d438bad919c6b07803fa718d0a65c52cb2fc9d78')
->pdf(array(
    "format"=>"A4",
    "landscape"=>true,
    "printBackground"=>false,
    "width"=>'1000'
))
->toBrowser("Inventar.pdf");

MyReportPDF.view.php

<?php
    error_reporting(0);
    use \koolreport\pivot\widgets\PivotTable;
?>
<html>
    <head>
        <meta charset="UTF-8">
    </head>
    <header>
        <h4>
        <?php 
            echo 'location <br>';
            echo 'location <br>';
            echo 'location <br>';
            echo 'location <br>';
            echo 'location <br>';
            echo 'location <br>';
            echo 'location <br>';
            echo 'location <br>';
            echo 'location <br>';
            echo 'location <br>';
        ?>
        </h4>
    </header>
    <body>
        <div style="width:100%;">
            <?php

            function translate( $v, $f ){

                switch ($v) {
                    case 'article_quantity - sum': return 'Artikel Menge';
                    case 'inventory_quantity - sum': return 'Inventur Menge';
                    case 'quantity_diff - sum': return 'Menge Diff';
                    case 'opened_by - count': return 'Geöffned bei';
                    case 'closed_by - count': return 'Geschloßen bei';
                    case 'detail_id - count': return 'Positionen';
                    case 'year': return 'Jahr';
                    case 'quarter': return 'Quartal';
                    case 'month': return 'Monat';
                    case 'day': return 'Tag';
                    case 'day_of_week': return 'Wochentag';
                    case 'location_text': return 'Standort';
                    case 'city': return 'Stadt';
                    case 'article_text': return 'Artikel';
                    case 'employee_text': return 'Mitarbeiter';
                    case 'duration_hours - sum': return 'Dauer (Std.)';
                    case 'duration_days - sum': return 'Dauer (Tage)';
                }
                $r = $v;

                $monthMap = array(
                    '' => '',
                    '1' => 'Januar',
                    '2' => 'Februar',
                    '3' => 'März',
                    '4' => 'April',
                    '5' => 'Mai',
                    '6' => 'Juni',
                    '7' => 'Juli',
                    '8' => 'August',
                    '9' => 'September',
                    '10' => 'Oktober',
                    '11' => 'November',
                    '12' => 'Dezember',
                );
                $dayMap = array(
                    '1' => 'Sonntag',
                    '2' => 'Montag',
                    '3' => 'Dienstag',
                    '4' => 'Mittwoch',
                    '5' => 'Donnerstag',
                    '6' => 'Freitag',
                    '7' => 'Samstag',
                );
                if ($f === 'month')
                    $r = $monthMap[$v];

                if ($f === 'day_of_week')
                    $r = $dayMap[$v];

                return $r;
            }
            PivotTable::create(array(
                "dataSource" => $this->dataStore('inventory'),
                // 'hideSubTotalRows' => true,
                // 'hideSubTotalColumns' => true,
                // 'hideGrandTotalRow' => true,
                // 'hideGrandTotalColumn' => true,
                "showDataHeaders" => true,
                "measures"=>array(
                    "inventory_quantity - sum", 
                    "article_quantity - sum",
                    "quantity_diff - sum",
                ),
                'map' => array(
                    'rowField' => function($rowField, $fieldInfo) {
                        return translate( $rowField, '' );
                    },
                    'columnField' => function($colField, $fieldInfo) {
                        return translate( $colField, '' );
                    },
                    'dataField' => function($dataField, $fieldInfo) {
                        return translate( $dataField, '' );
                    },
                    'waitingField' => function($waitingField, $fieldInfo) {
                        return translate( $waitingField, '' );
                    },
                    'dataHeader' => function($dataHeader, $headerInfo) {
                        return translate( $dataHeader, '' );
                    },
                    // 'columnHeader' => function($colHeader, $headerInfo) {
                    //     $v = $colHeader;
                    //     if ($headerInfo['fieldName'] === 'month')
                    //         $v = translate($v, $headerInfo['fieldName']);

                    //     return $v;
                    // },
                ),
                // "cssClass"=>array(
                //     "table"=>"table table-hover table-bordered"
                // )
            ));
            ?>
        </div>
    </body>
</html>
Ralf Föhring commented on Jan 8, 2020

I've changed MyReportPDF.view.php to this. I got rid of the <header>...</header>

<?php
    error_reporting(0);
    use \koolreport\pivot\widgets\PivotTable;
?>
<html>
    <head>
        <meta charset="UTF-8">
        <!-- <link rel="stylesheet" href="../assets/bs3/bootstrap.min.css" />
        <link rel="stylesheet" href="../assets/bs3/bootstrap-theme.min.css" />  -->
    </head>
    <body>
        <div style="width:100%; height:100%;">
        <?php 
            echo 'location <br>';
            echo 'location <br>';
            echo 'location <br>';
            echo 'location <br>';
            echo 'location <br>';
            echo 'location <br>';
            echo 'location <br>';
            echo 'location <br>';
            echo 'location <br>';
            echo 'location <br>';
            //$this->dataStore('location')->first()['text'];

            function translate( $v, $f ){

                switch ($v) {
                    case 'article_quantity - sum': return 'Artikel Menge';
                    case 'inventory_quantity - sum': return 'Inventur Menge';
                    case 'quantity_diff - sum': return 'Menge Diff';
                    case 'opened_by - count': return 'Geöffned bei';
                    case 'closed_by - count': return 'Geschloßen bei';
                    case 'detail_id - count': return 'Positionen';
                    case 'year': return 'Jahr';
                    case 'quarter': return 'Quartal';
                    case 'month': return 'Monat';
                    case 'day': return 'Tag';
                    case 'day_of_week': return 'Wochentag';
                    case 'location_text': return 'Standort';
                    case 'city': return 'Stadt';
                    case 'article_text': return 'Artikel';
                    case 'employee_text': return 'Mitarbeiter';
                    case 'duration_hours - sum': return 'Dauer (Std.)';
                    case 'duration_days - sum': return 'Dauer (Tage)';
                }
                $r = $v;

                $monthMap = array(
                    '' => '',
                    '1' => 'Januar',
                    '2' => 'Februar',
                    '3' => 'März',
                    '4' => 'April',
                    '5' => 'Mai',
                    '6' => 'Juni',
                    '7' => 'Juli',
                    '8' => 'August',
                    '9' => 'September',
                    '10' => 'Oktober',
                    '11' => 'November',
                    '12' => 'Dezember',
                );
                $dayMap = array(
                    '1' => 'Sonntag',
                    '2' => 'Montag',
                    '3' => 'Dienstag',
                    '4' => 'Mittwoch',
                    '5' => 'Donnerstag',
                    '6' => 'Freitag',
                    '7' => 'Samstag',
                );
                if ($f === 'month')
                    $r = $monthMap[$v];

                if ($f === 'day_of_week')
                    $r = $dayMap[$v];

                return $r;
            }
            PivotTable::create(array(
                "dataSource" => $this->dataStore('inventory'),
                // 'hideSubTotalRows' => true,
                // 'hideSubTotalColumns' => true,
                // 'hideGrandTotalRow' => true,
                // 'hideGrandTotalColumn' => true,
                "showDataHeaders" => true,
                "measures"=>array(
                    "inventory_quantity - sum", 
                    "article_quantity - sum",
                    "quantity_diff - sum",
                ),
                'map' => array(
                    'rowField' => function($rowField, $fieldInfo) {
                        return translate( $rowField, '' );
                    },
                    'columnField' => function($colField, $fieldInfo) {
                        return translate( $colField, '' );
                    },
                    'dataField' => function($dataField, $fieldInfo) {
                        return translate( $dataField, '' );
                    },
                    'waitingField' => function($waitingField, $fieldInfo) {
                        return translate( $waitingField, '' );
                    },
                    'dataHeader' => function($dataHeader, $headerInfo) {
                        return translate( $dataHeader, '' );
                    },
                    // 'columnHeader' => function($colHeader, $headerInfo) {
                    //     $v = $colHeader;
                    //     if ($headerInfo['fieldName'] === 'month')
                    //         $v = translate($v, $headerInfo['fieldName']);

                    //     return $v;
                    // },
                ),
                // "cssClass"=>array(
                //     "table"=>"table table-hover table-bordered"
                // )
            ));
            ?>
        </div>
    </body>
</html>

and now getting this:

Ralf Föhring commented on Jan 13, 2020

Hi, still no idea?

David Winterburn commented on Jan 14, 2020

Hi Ralf,

I guess it could be some js issue where there's a problem with retrieving PivotTable.js from your server to send to cloud. Please test this method:

  1. Open the file koolreport/pivot/widgets/PivotTable.tpl.php

  2. Replace this:

<table id=<?=$uniqueId?> 
    class='pivot-table table table-bordered' style='width:<?= $width ?>; visibility: hidden'>

with:

<table id=<?=$uniqueId?> 
    class='pivot-table table table-bordered' style='width:<?= $width ?>;'>

Then try cloud export again and let us know the result. Thanks!

Ralf Föhring commented on Jan 15, 2020

Hi, I've got new results. Indeed it looks like the visibility style is not applied. The table styles are also not applied. What should I check on my server in this case?

Result from server:

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
help needed

CloudExport