Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
227 views
in Technique[技术] by (71.8m points)

php - Mpdf depricated curly braces

My issue

I am trying to create a pdf file using MPDF but after I installed mpdf I get the following error that it uses depricated curly braces. I am using php 8.0.0 and my mpdf version is 6.1.

What I tried

  • change the curly braces to brackets but this broke the library completely saying non number values are encountered.

The errors I am getting after fixing the depricated curly braces are the following:

Warning: A non-numeric value encountered in C:xampphtdocsackendJaar2Project_webshopLibraryvendormpdfmpdfmpdf.php on line 30572

Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, string given in C:xampphtdocsackendJaar2Project_webshopLibraryvendormpdfmpdfclassestfontsuni.php:613 Stack trace: #0 C:xampphtdocsackendJaar2Project_webshopLibraryvendormpdfmpdfclassestfontsuni.php(202): TTFontFile->extractInfo(false, true, 0) #1 C:xampphtdocsackendJaar2Project_webshopLibraryvendormpdfmpdfmpdf.php(3880): TTFontFile->getMetrics('C:/xampp/htdocs...', 'dejavuserifcond...', 0, false, true, 0) #2 C:xampphtdocsackendJaar2Project_webshopLibraryvendormpdfmpdfmpdf.php(4246): mPDF->AddFont('dejavuserifcond...', '') #3 C:xampphtdocsackendJaar2Project_webshopLibraryvendormpdfmpdfmpdf.php(13621): mPDF->SetFont('dejavuserifcond...') #4 C:xampphtdocsackendJaar2Project_webshopLibraryvendormpdfmpdfmpdf.php(1287): mPDF->SetDefaultFont('serif') #5 C:xampphtdocsackendJaar2Project_webshopLibrarypdf_genereren.php(8): mPDF->__construct() #6 {main} thrown in C:xampphtdocsackendJaar2Project_webshopLibraryvendormpdfmpdfclassestfontsuni.php on line 613
  • reinstalled the library twice, reinstalled composer once
  • Upgrade to the latest stable php version (8.0.1)
<?php
ob_clean();
ob_start();

$rapport = ob_get_clean();
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new mPDF();
$mpdf->showImageErrors = true;
$mpdf->WriteHTML("<h1>Hello world..</h1>");
$mpdf->Output();
?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Update: mPDF is supported on PHP 8 since v8.0.10, there is no need to use a dedicated branch.


Turned out, because php8 is not supported yet in mpdf. I had to install a custom version of mpdf by doing composer require mpdf/mpdf dev-php8-support and that fixed all the issues.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...