I am writing a wordpress plugin and creating a function that generates an invoice and sends it by e-mail. There was a problem generating the PDF file. Each attempt to generate a PDF file ends with the error: Error detected. PDF generation aborted: “allow_url_include” directive is deprecated
My code:
$defaultConfig = (new MpdfConfigConfigVariables())->getDefaults(); $fontDirs = $defaultConfig['fontDir']; $defaultFontConfig = (new MpdfConfigFontVariables())->getDefaults(); $fontData = $defaultFontConfig['fontdata']; try { $mpdf = new MpdfMpdf([ 'fontDir' => array_merge($fontDirs, [ __DIR__ . '/mpdf2/vendor/mpdf/mpdf/ttfonts', ]), 'fontdata' => $fontData + [ 'roboto' => [ 'R' => 'Roboto-Regular.ttf', 'B' => 'Roboto-Bold.ttf', ] ], 'mode' => 'UTF-8', 'format' => 'A4', 'default_font_size' => '12', 'default_font' => 'roboto', 'margin_left' => 25, 'margin_top' => 25, 'margin_right' => 25, 'margin_bottom' => 25, 'debug' => true, ]); $dir = plugin_dir_path(__DIR__); $mpdf->SetDisplayMode('fullwidth'); $mpdf->WriteHTML($html); $mpdf->Output($dir . 'haccp/invoice_pdf/' . $invoice_name, 'F'); } catch (MpdfMpdfException $e) { // Note: safer fully qualified exception name used for catch // Process the exception, log, print etc. echo $e->getMessage(); }
Advertisement
Answer
mPDF is catching an error caused by you setting a allow_url_include
INI variable after upgrading to PHP 7.4 – either in ini_set
call or in PHP configuration (php.ini file, .htaccess, server configuration).
Remove the allow_url_include
setting change or rollback to PHP 7.3 or perhaps disable deprecated warnings.
See https://www.php.net/manual/en/filesystem.configuration.php