9

I'm using PHP 5.x and mPDF 6.x for long time.

This week I decide to upgrade system to PHP7.1 but still using mPDF6.

I face some problem after upgrading.

PROBLEM 1::

Console show error message: constructer with the same name as class name is deprecate.

I go through each php files and find classes, then replace constructer function with __construct(...)

PROBLEM 2::

Console show error message:: Can not assign property ID to $attr I go to file mPDF.php in function MergeCSS(...). I add new line of code at third line.

if (empty($attr)) { $attr = array();}

PROBLEM 3::

Console show error message following this:: "A non-numeric value encountered" at line 30648."

My solution to solve this problem is just::

  1. replace mPDF->ConvertSize() function in mPDF.php file with coding from MPDF7.

    By replace function ConvertSize() with function ConvertSize() and multiplyFontSize();

https://github.com/mpdf/mpdf/blob/development/src/SizeConverter.php

  1. Add constant to mPDF class

const SCALE = 72 / 25.4;

Hope this help for someone who face this problem.

Chanatip Yim
  • 356
  • 1
  • 3
  • 11

5 Answers5

8

For people who want a complete "A non-numeric value encountered" fix. Take a look at my forked repo of mpdf 6.1.3 with commit.

Bas Elbers
  • 91
  • 3
2

FYI: PHP7 throws a compile-time error when it encounters a switch statement with multiple default blocks. mpdf uses multiple default blocks in its switch statements.

Paul Allsopp
  • 622
  • 1
  • 9
  • 23
1

I have version 8.0.0 and the same error.

My solution was: in the file src/SizeConverter.php on the line 79 i had:

case '%':
            if ($fontsize && $usefontsize) {
                $size *= $fontsize / 100;
            } else {
                $size *= $maxsize / 100;
            }
            break;

Change to:

case '%':
            if ($fontsize && $usefontsize) {
                $size *= $fontsize / 100;
            } else {
                $maxsize = \str_replace('mm', '', $maxsize);

                $size *= $maxsize / 100;
            }
            break;
JazMagno
  • 121
  • 2
  • 3
1

Setting Margin To Numeric Value Solved For Me

before

    $mpdf = new \Mpdf\Mpdf([
        'margin_left' => '7em',
        'margin_right' => '7em',
        'margin_top' => '7em',
        'margin_bottom' => '7em',
    ]);

after

    $mpdf = new \Mpdf\Mpdf([
        'margin_left' => '7',
        'margin_right' => '7',
        'margin_top' => '7',
        'margin_bottom' => '7',
    ]);
SagarKapasi099
  • 418
  • 6
  • 8
0

I had this error because I was using the function writeText passing x and y as empty string, before with old mpdf version and php 5.6 it was working. Now I changed it to use zero instead.

Cassiano
  • 562
  • 5
  • 16