代码之家  ›  专栏  ›  技术社区  ›  Chhorn Soro

Yii2 mpdf更改下载的文件名

  •  2
  • Chhorn Soro  · 技术社区  · 7 年前

    我正在进行SiteController操作打印,这是我的代码

    $pdf = new Pdf([
                // set to use core fonts only
                'mode' => Pdf::MODE_UTF8, 
                // A4 paper format
                'format' => Pdf::FORMAT_A4, 
                // portrait orientation
                'orientation' => Pdf::ORIENT_PORTRAIT, 
                // stream to browser inline
                'destination' => Pdf::DEST_BROWSER, 
                'marginTop' => 5,
                'marginLeft' => 5,
                // your html content input
                'content' => $content,  
                // format content from your own css file if needed or use the
                // enhanced bootstrap css built by Krajee for mPDF formatting 
                'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
                // any css to be embedded if required
                'cssInline' => '.kv-heading-1{font-size:18px}', 
                 // set mPDF properties on the fly
                'options' => ['title' => 'Customer Invoice'],
                 // call mPDF methods on the fly
                'methods' => [ 
                 //   'SetHeader'=>['Krajee Report Header'], 
                   // 'SetFooter'=>['{PAGENO}'],
                ]
            ]);
    
    
            // return the pdf output as per the destination setting
            return $pdf->render();
    

    请帮忙!!!

    1 回复  |  直到 7 年前
        1
  •  4
  •   In0cybe    7 年前

    您可以使用属性filename:string(输出PDF文件名)更改文件名。

    $pdf = new Pdf([
            // set to use core fonts only
            'mode' => Pdf::MODE_UTF8, 
            //Name for the file
            'filename' => 'The_name_you_want',
            // A4 paper format
            'format' => Pdf::FORMAT_A4, 
            // portrait orientation
            'orientation' => Pdf::ORIENT_PORTRAIT, 
            // stream to browser inline
            'destination' => Pdf::DEST_BROWSER, 
            'marginTop' => 5,
            'marginLeft' => 5,
            // your html content input
            'content' => $content,  
            // format content from your own css file if needed or use the
            // enhanced bootstrap css built by Krajee for mPDF formatting 
            'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
            // any css to be embedded if required
            'cssInline' => '.kv-heading-1{font-size:18px}', 
             // set mPDF properties on the fly
            'options' => ['title' => 'Customer Invoice'],
             // call mPDF methods on the fly
            'methods' => [ 
             //   'SetHeader'=>['Krajee Report Header'], 
               // 'SetFooter'=>['{PAGENO}'],
            ]
        ]);
    
    
        // return the pdf output as per the destination setting
        return $pdf->render();