Ce n'est pas super facile. Si vous voulez juste votre texte dans l'essai d'en-tête de PDF:
echo ExportMenu::widget([
'dataProvider' => $dataProvider,
'columns' => $gridColumns,
'filename' => 'Exported File',
'fontAwesome' => true,
'exportConfig' => [
ExportMenu::FORMAT_PDF => [
'pdfConfig' => [
'methods' => [
'SetHeader' => ['Your Title Here'],
],
],
],
],
]);
Mais si vous le voulez dans le corps de PDF Je suppose que vous devez étendre kartik\export\ExportMenu
et passer outre renderPDF()
comme:
class MyExportMenu extends \kartik\export\ExportMenu
{
protected function renderPDF($file)
{
// Default PDF paper size
$excel = $this->_objPHPExcel;
$sheet = $this->_objPHPExcelSheet;
/**
* @var \PHPExcel_Writer_HTML $w
*/
$w = $this->_objPHPExcelWriter;
$page = $sheet->getPageSetup();
$orientation = $page->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE ? 'L' : 'P';
$properties = $excel->getProperties();
$settings = ArrayHelper::getValue($this->exportConfig, $this->_exportType, []);
$useInlineCss = ArrayHelper::getValue($settings, 'useInlineCss', false);
$config = ArrayHelper::getValue($settings, 'pdfConfig', []);
$w->setUseInlineCss($useInlineCss);
$config = array_replace_recursive(
[
'orientation' => strtoupper($orientation),
'methods' => [
'SetTitle' => $properties->getTitle(),
'SetAuthor' => $properties->getCreator(),
'SetCreator' => $properties->getCreator(),
'SetSubject' => $properties->getSubject(),
'SetKeywords' => $properties->getKeywords(),
],
'cssFile' => '',
'content' => '<h1>Your Title Here</h1>' // <- title here
. $w->generateHTMLHeader(false)
. $w->generateSheetData()
. $w->generateHTMLFooter(),
],
$config
);
if (!$this->stream) {
$config['destination'] = Pdf::DEST_FILE;
$config['filename'] = $file;
} else {
$config['destination'] = Pdf::DEST_DOWNLOAD;
$extension = ArrayHelper::getValue($settings, 'extension', 'pdf');
$config['filename'] = $this->filename . '.' . $extension;
}
$pdf = new Pdf($config);
echo $pdf->render();
}
}
Et puis vous avez utiliser votre classe à la place. Je ne suis pas sûr à 100% que cela fonctionne, pas testé.
Merci pour la réponse. Btw, pourriez-vous s'il vous plaît voir ma question dans https://stackoverflow.com/questions/45319792/yii2-export-kartik-v? Je veux exporter toutes les tables dans un document – r34627673
J'ai essayé le code ci-dessus, mais ne fonctionnait pas – r34627673