kartik-v / yii2-mpdf

A Yii2 wrapper component for the mPDF library which generates PDF files from UTF-8 encoded HTML.
http://demos.krajee.com/mpdf
Other
161 stars 150 forks source link

could not generate 2+ pdf per time #97

Closed konstpap2 closed 4 years ago

konstpap2 commented 5 years ago

Prerequisites

I have a function to generate pdf-file in Yii2

private function savePDFPrint($data,$path)
    {
       ....
       $filename = $data['content'];
        ...
        $content = $this->renderPartial('/result/resultPrint',['id' => $id], true, true);// быстро
        $pdfPrint = new Pdf([
            'mode' => Pdf::MODE_UTF8,
            'filename' => $path,
            'destination' => Pdf::DEST_FILE,
            'content' => $content,
            'cssFile' => $cssfile,
            'options' => [
            ],
            'methods' => [
                'SetTitle' => $title,
                'SetSubject' => $subject,
                'SetAuthor' => $author,
                'SetCreator' => $creator,
                'SetKeywords' => $keywords,
            ]
        ]);
        $pdfPrint->render();
        ...
        return true;
    }

when i trying to call this function more than once

...
savePDFPrint($data1,$path1);
savePDFPrint($data2,$path2);
...

i got a error

"PHP Notice 'yii\base\ErrorException' with message 'Constant _MPDF_TEMP_PATH already defined"

I solved this in this way

/yii2-mpdf/src/Pdf.php, line 249
if( !defined( '_MPDF_TEMP_PATH' ))
   static::definePath('_MPDF_TEMP_PATH', "{$prefix}tmp{$s}");
if( !defined( '_MPDF_TTFONTDATAPATH' ))
   static::definePath('_MPDF_TTFONTDATAPATH', "{$prefix}ttfontdata{$s}");

But may be you have a better solution...

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.