3

我正在尝试找出一种在导出时修改 PDF 标题的方法。

现在标题说类似 Yii2 Grid Export (PDF) Grid Export。

这是我用来尝试修改它的代码:

            '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'
                    ]
                ],
            ],
4

2 回答 2

2

只需扩展这个精美的 kartik 网格(http://demos.krajee.com/grid)并覆盖 run() 和 initExport() 类似:

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();        
    }

}

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

于 2016-03-02T22:30:21.277 回答
1

你必须自定义你的 GridView

 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 在哪里

$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文档

于 2019-05-16T12:23:56.467 回答