33/**
44 * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2017
55 * @package yii2-mpdf
6- * @version 1.0.2
6+ * @version 1.0.3
77 */
88
99namespace kartik \mpdf ;
1212use Yii ;
1313use yii \base \Component ;
1414use yii \base \InvalidConfigException ;
15- use yii \base \ InvalidParamException ;
15+ use yii \web \ Response ;
1616
1717/**
1818 * 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
145145 /**
146146 * @var string css file to prepend to the PDF
147147 */
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 ' ;
149149 /**
150150 * @var string additional inline css to append after the cssFile
151151 */
@@ -254,6 +254,7 @@ public function initTempPaths()
254254 * Renders and returns the PDF output. Uses the class level property settings.
255255 *
256256 * @return mixed
257+ * @throws InvalidConfigException
257258 */
258259 public function render ()
259260 {
@@ -344,16 +345,16 @@ public function addPdfAttachment($filePath)
344345 * Calls the Mpdf method with parameters
345346 *
346347 * @param string $method the Mpdf method / function name
347- * @param array $params the Mpdf parameters
348+ * @param array $params the Mpdf parameters
348349 *
349350 * @return mixed
350- * @throws InvalidParamException
351+ * @throws InvalidConfigException
351352 */
352353 public function execute ($ method , $ params = [])
353354 {
354355 $ api = $ this ->getApi ();
355356 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'. " );
357358 }
358359 if (!is_array ($ params )) {
359360 $ params = [$ params ];
@@ -392,11 +393,11 @@ public function output($content = '', $file = '', $dest = self::DEST_BROWSER)
392393 }
393394 }
394395
395- $ is_web_response = (Yii::$ app ->response instanceof \ yii \ web \ Response);
396+ $ is_web_response = (Yii::$ app ->response instanceof Response);
396397
397398 // For non-web response, or for file / string output, use the mPDF function as it is
398399 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 );
400401 }
401402
402403 // Workaround for browser & download output.
@@ -406,26 +407,24 @@ public function output($content = '', $file = '', $dest = self::DEST_BROWSER)
406407 // - Set the destination to string
407408 // - Set response headers through yii\web\Response
408409 $ output = $ api ->Output ($ file , self ::DEST_STRING );
409-
410410 $ headers = Yii::$ app ->response ->getHeaders ();
411-
412- $ headers ->set ('Content-Type ' , 'application/pdf ' );
411+ $ headers ->set ('Content-Type ' , 'application/pdf ' );
413412 $ 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 ' );
418417
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+ }
423422
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+ }
429428
430429 return $ output ;
431430 }
@@ -445,7 +444,7 @@ protected function parseFormat()
445444 /**
446445 * Appends the given attachment to the generated PDF
447446 *
448- * @param Mpdf $api the Mpdf API instance
447+ * @param Mpdf $api the Mpdf API instance
449448 * @param string $attachment the attachment name
450449 */
451450 private function writePdfAttachment ($ api , $ attachment )
0 commit comments