首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >kartik GridView Yii2 -如何配置PDF的导出配置(页眉、页脚、标题)

kartik GridView Yii2 -如何配置PDF的导出配置(页眉、页脚、标题)
EN

Stack Overflow用户
提问于 2015-07-02 23:57:58
回答 2查看 2.9K关注 0票数 3

当我做导出时,我正试图找出一种修改PDF头的方法。

现在,标题说的是类似于Yii2网格导出(PDF)的网格导出。

下面是我用来修改它的代码:

代码语言:javascript
复制
            'exportConfig' => [
                GridView::PDF => [
                    'label' => 'PDF',
                    'filename' => 'Preceptors',
                    'title' => 'Preceptors',                        
                    'options' => ['title' => 'Preceptor List','author' => 'Me'],                        
                ],
                GridView::CSV => [
                    'label' => 'CSV',
                    'filename' => 'Preceptors',
                    'options' => ['title' => 'Preceptor List'],                                             
                ],
            ],

            'export' => [
                'PDF' => [
                    'options' => [
                        'title' => 'Preceptors',
                        'subject' => 'Preceptors',
                        'author' => 'NYCSPrep CIMS',
                        'keywords' => 'NYCSPrep, preceptors, pdf'
                    ]
                ],
            ],
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-03-02 22:30:21

只需扩展这个精细的kartik网格(http://demos.krajee.com/grid)和overide run()和initExport(),如下所示:

代码语言:javascript
复制
namespace common\widgets;

use Yii;
use yii\web\JsExpression;
use yii\helpers\ArrayHelper;


class GridView extends \kartik\grid\GridView
{
    protected function initExport() {
        ... copy original and set whatever you like
    }

    public function run() {
        parent::run();
        $this->initExport();        
    }

}

当然,根据需要设置名称空间。

票数 2
EN

Stack Overflow用户

发布于 2019-05-16 12:23:56

您必须自定义GridView

代码语言:javascript
复制
 GridView::PDF => [
    'filename' => 'Preceptors',
    'config' => [
      'methods' => [
        'SetHeader' => [
          ['odd' => $pdfHeader, 'even' => $pdfHeader]
        ],
        'SetFooter' => [
          ['odd' => $pdfFooter, 'even' => $pdfFooter]
        ],
      ],
      'options' => [
        'title' => 'Preceptors',
        'subject' => 'Preceptors',
        'keywords' => 'pdf, preceptors, export, other, keywords, here'
      ],
    ]
  ],

$pdfHeader和$pdfFooter

代码语言:javascript
复制
$pdfHeader = [
    'L'    => [
        'content' => 'LEFT CONTENT (HEAD)',
    ],
    'C'    => [
        'content'     => 'CENTER CONTENT (HEAD)',
        'font-size'   => 10,
        'font-style'  => 'B',
        'font-family' => 'arial',
        'color'       => '#333333',
    ],
    'R'    => [
        'content' => 'RIGHT CONTENT (HEAD)',
    ],
    'line' => true,
];

$pdfFooter = [
    'L'    => [
        'content'     => 'LEFT CONTENT (FOOTER)',
        'font-size'   => 10,
        'color'       => '#333333',
        'font-family' => 'arial',
    ],
    'C'    => [
        'content' => 'CENTER CONTENT (FOOTER)',
    ],
    'R'    => [
        'content'     => 'RIGHT CONTENT (FOOTER)',
        'font-size'   => 10,
        'color'       => '#333333',
        'font-family' => 'arial',
    ],
    'line' => true,
];

mPdf文档

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31196475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档