2

I'm working on SiteController action print and here is my code

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

when this action is triggered, it render the pdf on the browser ,but when I click download button the default filename is "print". How can I change it?

Please help!!!

Chhorn Soro
  • 3,061
  • 8
  • 27
  • 43
  • Possible duplicate of [Changing the default filename when using mPDF](https://stackoverflow.com/questions/34687293/changing-the-default-filename-when-using-mpdf) – Yupik Aug 03 '17 at 05:36
  • May I know what this script `'options' => ['title' => 'Customer Invoice'],` for? I've set script like this in my file, but it didn't show **Customer Service** in anywhere. Thanks – Blackjack Oct 15 '17 at 12:20

1 Answers1

4

you can change the name of the file with the property filename: string, the output PDF filename.

$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();
In0cybe
  • 301
  • 1
  • 2
  • 11