Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines
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");
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 Ø';
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>
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!
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!
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
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>
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:
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:
Open the file koolreport/pivot/widgets/PivotTable.tpl.php
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!
Let KoolReport help you to make great reports. It's free & open-source released under MIT license.
Download KoolReport View demo