Skip to content

Commit c1b6dec

Browse files
committed
Update MPDFResponseFormatter.php
1 parent 3d69866 commit c1b6dec

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

MPDFResponseFormatter.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ class MPDFResponseFormatter extends Component implements ResponseFormatterInterf
7676
public $outputName = '';
7777
public $outputDest = 'I';
7878

79+
/**
80+
* @var \Closure
81+
*/
82+
public $beforeWrite;
83+
7984
/**
8085
* @inheritdoc
8186
*/
@@ -123,10 +128,14 @@ protected function formatMPDF($response)
123128
$this->setMPDFFooter($mpdf, $this->footer);
124129

125130
if (is_string($response->data)) {
131+
if ($this->beforeWrite !== null)
132+
call_user_func($this->beforeWrite, $mpdf);
126133
$mpdf->WriteHTML($response->data, 2);
127134
} else if (is_array($response->data)) {
128135
$this->setOptions($mpdf, $response->data['options']);
129136
$this->setMPDFOptions($mpdf, $response->data['mPDFOptions']);
137+
if ($this->beforeWrite !== null)
138+
call_user_func($this->beforeWrite, $mpdf);
130139
if (isset($response->data['content']))
131140
$mpdf->WriteHTML($response->data['content'], 2);
132141
}
@@ -141,7 +150,7 @@ protected function setOptions($mpdf, $options)
141150
{
142151
if (!is_array($options))
143152
return;
144-
153+
145154
foreach ($options as $attribute => $value) {
146155
$this->$attribute = $value;
147156

0 commit comments

Comments
 (0)