Closed antichris closed 6 years ago
When calling yii2tech\html2pdf\Manager::convert() with mPDF as the converter, the following exception is thrown:
yii2tech\html2pdf\Manager::convert()
Mpdf\MpdfException: Temporary files directory "/my-project/vendor/mpdf/mpdf/src/Config/../../tmp" is not writable in /my-project/vendor/mpdf/mpdf/src/Cache.php:17 Stack trace: #0 /my-project/vendor/mpdf/mpdf/src/Mpdf.php(983): Mpdf\Cache->__construct('/my-project/ven...') #1 /my-project/vendor/yii2tech/html2pdf/src/converters/Mpdf.php(42): Mpdf\Mpdf->__construct(Array) #2 /my-project/vendor/yii2tech/html2pdf/src/BaseConverter.php(33): yii2tech\html2pdf\converters\Mpdf->convertInternal('<!DOCTYPE html>...', '/my-project/run...', Array) #3 /my-project/vendor/yii2tech/html2pdf/src/Manager.php(224): yii2tech\html2pdf\BaseConverter->convert('<!DOCTYPE html>...', '/my-project/run...', Array) #4 /my-project/controllers/SiteController.php(23): yii2tech\html2pdf\Manager->convert('<!DOCTYPE html>...') #5 [internal function]: app\controllers\backend\SiteController->actionPdf() #6 /my-project/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array) #7 /my-project/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array) #8 /my-project/vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction('pdf', Array) #9 /my-project/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('backend/site/pd...', Array) #10 /my-project/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request)) #11 /my-project/web/index.php(31): yii\base\Application->run() #12 {main}
This happens because the constructor of the main mPDF object requires tempDir to be already properly configured when instantiating its Mpdf\Cache in Mpdf\Mpdf::__construct() (line 983 in v7.1.0):
tempDir
Mpdf\Cache
Mpdf\Mpdf::__construct()
$this->cache = new Cache($config['tempDir']);
the default value for which comes from Mpdf\Config\ConfigVariables::$defaults:
Mpdf\Config\ConfigVariables::$defaults
$this->defaults = [ ... 'tempDir' => __DIR__ . '/../../tmp', ... ];
but your yii2tech\html2pdf\converters\Mpdf::convertInternal() does not set it to a valid value when instantiating mPDF:
yii2tech\html2pdf\converters\Mpdf::convertInternal()
$pdf = new \Mpdf\Mpdf([ 'mode' => $charset, 'format' => $pageSize, ]);
so that even setting tempDir properly in yii2tech\html2pdf\converters\Mpdf::$defaultOptions has no effect.
yii2tech\html2pdf\converters\Mpdf::$defaultOptions
Get cracking! :wink:
EDIT:
Resolved by commit ea434421b78485335a618778dc58caae48786ee8
When calling
yii2tech\html2pdf\Manager::convert()
with mPDF as the converter, the following exception is thrown:This happens because the constructor of the main mPDF object requires
tempDir
to be already properly configured when instantiating itsMpdf\Cache
inMpdf\Mpdf::__construct()
(line 983 in v7.1.0):the default value for which comes from
Mpdf\Config\ConfigVariables::$defaults
:but your
yii2tech\html2pdf\converters\Mpdf::convertInternal()
does not set it to a valid value when instantiating mPDF:so that even setting
tempDir
properly inyii2tech\html2pdf\converters\Mpdf::$defaultOptions
has no effect.Get cracking! :wink:
EDIT: