How to set landscape format in kartik export menu? - yii2

Kartik export menu exports the data in portrait format by default. I want to make it landscape but i don't know how to make it landscape.
Please help someone.
Thanks in advance.

'exportConfig' => [
\kartik\export\ExportMenu::FORMAT_PDF => [
'pdfConfig' => [
'orientation' => 'L',
],
],
],

Related

How to make selective asset redefinition in Yii2?

I want to overwrite a css code of an existing asset, for example “kartik\form\ActiveFormAsset”. If i follow the official guide, i will do this:
'components' => [
'assetManager' => [
'bundles' => [
'kartik\form\ActiveFormAsset' => [
'sourcePath' => null, // do not publish the bundle
'basePath' => '#webroot',
'baseUrl' => '#web',
'css' => [
'/custom.css',
]
],
],
],
],
But it automatically changes a path to a js file which i want to keep up-to-date and don’t do any changes.
So, how to overwrite asset only for css, not for js?
If you don't need an asset assignment or you want overwrite the assignmente you could try using registering scripts in your view .
$this->registerCssFile("#web/css/themes/black-and-white.css", [
'depends' => [\yii\bootstrap\BootstrapAsset::class],
'media' => 'print',
], 'css-print-theme');
see yii2 guide and reference for this
https://www.yiiframework.com/doc/guide/2.0/en/output-client-scripts
https://www.yiiframework.com/doc/api/2.0/yii-web-view

Using different value for same key in yii2 i18n

i', trying to incorporate multi-language functionality into my project and i have a situation whereby the same key has multiple meaning and i wounder how to fix this for example i have in my project
return[
'Home' => '首页', //meaning ‘Home page’
]`
Now the case is i also have some over words with Home as the key but have another meaning like thus
'Home' => '主队', //meaning ‘Home team’
how can actualize this using the same key "Home" but giving them different meaning on different part of my project
There are two options how to deal with situation like that.
Using categories
The proper way would be using different categories for different meanings. To do that you have to configure the translations for two (or more) different categories, for example like that.
'components' => [
// ...
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'fileMap' => [
'app' => 'app.php',
'app/match' => 'match.php',
],
],
],
],
],
Your app.php translation file will look like this
return [
'Home' => '首页', //meaning ‘Home page’
];
And your match.php translation file will look like this:
return [
'Home' => '主队', //meaning ‘Home team’
];
Then you will call translations like this where the meaning is home page:
Yii::t('app', 'Home');
And like this where the meaning is home team:
Yii::t('app/match', 'Home');
If you are using yii message command to generate translation files you might need to set the fileMap in it's config to make sure all files are generated properly.
Forcing translations for source language
This way is more like hack than proper solution. You can force the i18n component to translate text even if the source and app language are same. You can use that to have two different keys that are same in the english translations but different in other.
The configuration would look like:
'components' => [
// ...
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'forceTranslation' => true,
'fileMap' => [
'app' => 'app.php',
],
],
],
],
],
The english app.php translation file:
return [
'Home page' => 'Home',
'Home team' => 'Home',
];
The chinese app.php translation file:
return [
'Home page' => '首页',
'Home team' => '主队',
];
You will use Yii::t('app', 'Home page') or Yii::t('app', 'Home team') in your code.

Chartjs does not show on pdf in yii2 despite showing in html view

I have developed an app using Yii2, mpdf and chartjs. The page works well in html but doesn't show the chart when I export to pdf using mpdf. How can I solve this?
<?= ChartJs::widget([
'type' => 'line',
'options' => [
'height' => 400,
'width' => 400,
'show_as_html'=> true
],
'data' => [
'labels' => ["January", "February", "March", "April", "May", "June", "July"],
'datasets' => [
[
'label' => "Sales",
'backgroundColor' => "rgba(255,99,132,0.2)",
'borderColor' => "rgba(255,99,132,1)",
'pointBackgroundColor' => "rgba(255,99,132,1)",
'pointBorderColor' => "#fff",
'pointHoverBackgroundColor' => "#fff",
'pointHoverBorderColor' => "rgba(255,99,132,1)",
'data' => [28, 48, 40, 19, 96, 27, 100]
]
]
]
]);
?>
You can see in the MPDF docs: https://mpdf.github.io/html-support/html-tags.html
that canvas and script tags are not supported. in the case of charts, most use canvas, you can see that chartsjs also uses canvas to render its charts. https://www.chartjs.org/docs/latest/general/responsive.html
Most PDF generator does not support rich HTML and charts.
I suggest you use phantomJS for generating pdf.
http://phantomjs.org/
http://jonnnnyw.github.io/php-phantomjs/
for PDF: http://jonnnnyw.github.io/php-phantomjs/4.0/3-usage/#output-to-pdf

How can I disable drag and drop on extension Redactor v10.1.1 for Yii2 framework?

I'm using yii2-redactor. I'm trying to generally disable file drag and drop. Is there an option for this?
Thank you.
Try with clientOptions. Docs, For example
<?= $form->field($model, 'body')->widget(\yii\redactor\widgets\Redactor::className(), [
'clientOptions' => [
'dragUpload' => false
]
])?>
According to latest Docs, For example
<?= $form->field($model, 'body')->widget(\yii\redactor\widgets\Redactor::className(), [
'clientOptions' => [
'dragImageUpload' => false,
'dragFileUpload' => false
]
])?>
Option dragUpload didn't work for me. I found here a couple of options which worked for me. Example below.
<?= $form->field($model, 'body')->widget(\yii\redactor\widgets\Redactor::className(), [
'clientOptions' => [
'dragImageUpload' => false,
'dragFileUpload' => false
]
])?>

Edit content of export menu in yii2

I use export menu on my yii2 project. I download it from demos.krajee.com. I have been success to use it, but I want to edit content like in pdf, so it have title/header or footer or page number. How to make it?
There are at least two ways to do that.
For example you can set it as default setting in
Yii::$container->set('kartik\grid\GridView', [
'summary' => "Showing {begin} - {end} from {totalCount} records",
'captionOptions' => ['style' => 'font-size:0em;'],
'panel' => [
'heading' => false,
'before' => '{summary}',
'after' => '{pager}',
'footer' => false,
],
'hover' => true,
'toolbar' => [
'{export}',
'{toggleData}',
],
'export' =>[
'showConfirmAlert' => false,
],
'exportConfig' => [
kartik\grid\GridView::PDF => [
'label' => 'Save as PDF',
'config' => [
'methods' => [
'SetHeader' => ['Header'],
'SetFooter' => ['Footer whatever: ' . strftime("%c") . '||Page {PAGENO}'],
]
],
],
],
...
Or pass the settings individually to each widget in every view.
You can use methods in wrapper http://demos.krajee.com/mpdf#settings (look for methods) or directly from mpdf class if you need something more complicated.