Open Pepita73 opened 3 years ago
I also have the same problem, I don't know how to create MPDF constructor to pass parameters
I have same problem with MPDF, can you fix it, please?
You can create your own writer to save pdf from word
final class MyMPDF extends \PhpOffice\PhpWord\Writer\PDF\MPDF
{
protected function createExternalWriterInstance()
{
$mPdfClass = $this->getMPdfClassName();
return new $mPdfClass([
'tempDir' => \PhpOffice\PhpWord\Settings::getTempDir(),
]);
}
private function getMPdfClassName(): string
{
if ($this->includeFile != null) {
// MPDF version 5.*
return '\mpdf';
}
// MPDF version > 6.*
return '\Mpdf\Mpdf';
}
}
and call it:
$phpWord = \PhpOffice\PhpWord\IOFactory::load($filePath);
Settings::setTempDir(sys_get_temp_dir());
$mpdfWriter = new MyMPDF($phpWord);
$mpdfWriter->save($filePath);
Is your feature request related to a problem? Please describe.
The mpdf package use self temp directory like vendor/mpdf/mpdf/tmp. Usually the vendor directories not writable for php (cli or web), only readable. So we get warning and empty pdf file.
Temporary files directory "...vendor/mpdf/mpdf/src/Config/../../tmp" is not writable
But PHPWord settings can store this configuration.Describe the solution you'd like
change line here: https://github.com/PHPOffice/PHPWord/blob/develop/src/PhpWord/Writer/PDF/MPDF.php#L56
Additional context
We use word template with header and footer section, but - if hacking the tempDir - these sections not transferred to the pdf file. If you can, please fix it also.