Fatal error: Switch statements may only contain one default clause in mpdf.php

ZiaUllahZia picture ZiaUllahZia · Nov 8, 2017 · Viewed 14.1k times · Source

I am using mPDF and it is working fine with localhost. I upload the project to live server and it is not generating pdf correctly.

<?php

// HTML ommited

$body = ob_get_clean();

include ("mpdf/mpdf.php");

$mpdf = new mPDF('+aCJK', 'A4', '', '', 0, 0, 0, 0, 0, 0);

$mpdf->WriteHTML($body);

$mpdf->Output('SaveToPDF.pdf', 'D');

On the top, I put the error show code. To see the error what is going wrong I have the following error.

Fatal error: Switch statements may only contain one default clause in /customers/d/e/a/....URL..GO..HERE/mpdf.php on line 1432

I am using PHP Version 5.6.31 on my Localhost and on live I am using one.com and there I can switch to different PHP versions, and I tried all. i.e. 5.6, 7.0, 7.1, 7.2 beta

I am using mPDF 5.7 and it is not composer version. I wanted to use chines character for my pdf and it good support available in 5.7. That's why I chose older version

Answer

Ivan Kalita picture Ivan Kalita · Nov 8, 2017

Old mpdf versions don't support PHP7, unfortunately (mpdf issue). You can either:

  1. Switch to actual mpdf version and use this workaround for chinese fonts;
  2. Or change your live server PHP to 5.6 (PHP RFC multiple default cases syntax error);
  3. Or fix this switch issue in mpdf source yourself (people discussed the possible solution in this hhvm issue), you just need to remove one of the default statements.