3
3
/**
4
4
* @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2017
5
5
* @package yii2-mpdf
6
- * @version 1.0.2
6
+ * @version 1.0.3
7
7
*/
8
8
9
9
namespace kartik \mpdf ;
12
12
use Yii ;
13
13
use yii \base \Component ;
14
14
use yii \base \InvalidConfigException ;
15
- use yii \base \ InvalidParamException ;
15
+ use yii \web \ Response ;
16
16
17
17
/**
18
18
* The Pdf class is a Yii2 component that allows to convert HTML content to portable document format (PDF). It allows
@@ -145,7 +145,7 @@ class Pdf extends Component
145
145
/**
146
146
* @var string css file to prepend to the PDF
147
147
*/
148
- public $ cssFile = '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css ' ;
148
+ public $ cssFile = '@vendor/kartik-v/yii2-mpdf/src/ assets/kv-mpdf-bootstrap.min.css ' ;
149
149
/**
150
150
* @var string additional inline css to append after the cssFile
151
151
*/
@@ -254,6 +254,7 @@ public function initTempPaths()
254
254
* Renders and returns the PDF output. Uses the class level property settings.
255
255
*
256
256
* @return mixed
257
+ * @throws InvalidConfigException
257
258
*/
258
259
public function render ()
259
260
{
@@ -344,16 +345,16 @@ public function addPdfAttachment($filePath)
344
345
* Calls the Mpdf method with parameters
345
346
*
346
347
* @param string $method the Mpdf method / function name
347
- * @param array $params the Mpdf parameters
348
+ * @param array $params the Mpdf parameters
348
349
*
349
350
* @return mixed
350
- * @throws InvalidParamException
351
+ * @throws InvalidConfigException
351
352
*/
352
353
public function execute ($ method , $ params = [])
353
354
{
354
355
$ api = $ this ->getApi ();
355
356
if (!method_exists ($ api , $ method )) {
356
- throw new InvalidParamException ("Invalid or undefined Mpdf method ' {$ method }' passed to 'Pdf::execute'. " );
357
+ throw new InvalidConfigException ("Invalid or undefined Mpdf method ' {$ method }' passed to 'Pdf::execute'. " );
357
358
}
358
359
if (!is_array ($ params )) {
359
360
$ params = [$ params ];
@@ -392,11 +393,11 @@ public function output($content = '', $file = '', $dest = self::DEST_BROWSER)
392
393
}
393
394
}
394
395
395
- $ is_web_response = (Yii::$ app ->response instanceof \ yii \ web \ Response);
396
+ $ is_web_response = (Yii::$ app ->response instanceof Response);
396
397
397
398
// For non-web response, or for file / string output, use the mPDF function as it is
398
399
if (!$ is_web_response || in_array ($ dest , [self ::DEST_FILE , self ::DEST_STRING ])) {
399
- return $ api ->Output ($ file , $ dest );
400
+ return $ api ->Output ($ file , $ dest );
400
401
}
401
402
402
403
// Workaround for browser & download output.
@@ -406,26 +407,24 @@ public function output($content = '', $file = '', $dest = self::DEST_BROWSER)
406
407
// - Set the destination to string
407
408
// - Set response headers through yii\web\Response
408
409
$ output = $ api ->Output ($ file , self ::DEST_STRING );
409
-
410
410
$ headers = Yii::$ app ->response ->getHeaders ();
411
-
412
- $ headers ->set ('Content-Type ' , 'application/pdf ' );
411
+ $ headers ->set ('Content-Type ' , 'application/pdf ' );
413
412
$ headers ->set ('Content-Transfer-Encoding ' , 'binary ' );
414
- $ headers ->set ('Cache-Control ' , 'public, must-revalidate, max-age=0 ' );
415
- $ headers ->set ('Pragma ' , 'public ' );
416
- $ headers ->set ('Expires ' , 'Sat, 26 Jul 1997 05:00:00 GMT ' );
417
- $ headers ->set ('Last-Modified ' , gmdate ('D, d M Y H:i:s ' ) . ' GMT ' );
413
+ $ headers ->set ('Cache-Control ' , 'public, must-revalidate, max-age=0 ' );
414
+ $ headers ->set ('Pragma ' , 'public ' );
415
+ $ headers ->set ('Expires ' , 'Sat, 26 Jul 1997 05:00:00 GMT ' );
416
+ $ headers ->set ('Last-Modified ' , gmdate ('D, d M Y H:i:s ' ) . ' GMT ' );
418
417
419
- if (!isset ($ _SERVER ['HTTP_ACCEPT_ENCODING ' ]) || empty ($ _SERVER ['HTTP_ACCEPT_ENCODING ' ])) {
420
- // don't use length if server using compression
421
- $ headers ->set ('Content-Length ' , strlen ($ output ));
422
- }
418
+ if (!isset ($ _SERVER ['HTTP_ACCEPT_ENCODING ' ]) || empty ($ _SERVER ['HTTP_ACCEPT_ENCODING ' ])) {
419
+ // don't use length if server using compression
420
+ $ headers ->set ('Content-Length ' , strlen ($ output ));
421
+ }
423
422
424
- if ($ dest == self ::DEST_BROWSER ) {
425
- $ headers ->set ('Content-Disposition ' , 'inline; filename=" ' . $ file . '" ' );
426
- } else {
427
- $ headers ->set ('Content-Disposition ' , 'attachment; filename=" ' . $ file . '" ' );
428
- }
423
+ if ($ dest == self ::DEST_BROWSER ) {
424
+ $ headers ->set ('Content-Disposition ' , 'inline; filename=" ' . $ file . '" ' );
425
+ } else {
426
+ $ headers ->set ('Content-Disposition ' , 'attachment; filename=" ' . $ file . '" ' );
427
+ }
429
428
430
429
return $ output ;
431
430
}
@@ -445,7 +444,7 @@ protected function parseFormat()
445
444
/**
446
445
* Appends the given attachment to the generated PDF
447
446
*
448
- * @param Mpdf $api the Mpdf API instance
447
+ * @param Mpdf $api the Mpdf API instance
449
448
* @param string $attachment the attachment name
450
449
*/
451
450
private function writePdfAttachment ($ api , $ attachment )
0 commit comments