html2pdf icon indicating copy to clipboard operation
html2pdf copied to clipboard

Php 7.4 with spipu/html2pdf 5.2 ; count(): Parameter must be an array or an object that implements Countable

Open Mahdjou opened this issue 3 years ago • 2 comments

Hello !

I'm a junior dev and i'm struggling with an error that i saw as an issue in this Github and tried to fix it on my project ;

A PHP Error was encountered
Severity: Warning

Message: count(): Parameter must be an array or an object that implements Countable

Filename: src/Html2Pdf.php

Line Number: 5150 , 5152, 5153

I tried all that was on the issues #577 #504 #420 and #407 ....

Can you help me to figure out how and where to fix that ?

Thank you for your work !

Mahdjou avatar Oct 19 '21 10:10 Mahdjou

Hi,

it seems that the error occurs when the table is not good (not the same number of columns on each row) or empty. And i did not put any security on it...

can you provide a little HTML example that cause this pb ?

thanks

spipu avatar Oct 19 '21 10:10 spipu

Hi !

Yeah of course i have this before my page tag;

</div>object(Spipu\Html2Pdf\Exception\ImageException)#319 (8) {
  ["image":protected]=&gt;
  string(0) ""
  ["message":protected]=&gt;
  string(38) "Unable to get the size of the image []"
  ["string":"Exception":private]=&gt;
  string(0) ""
  ["code":protected]=&gt;
  int(2)
  ["file":protected]=&gt;
  string(86) "/var/www/html/intranet/logiciel-codeigniter-dev/vendor/spipu/html2pdf/src/Html2Pdf.php"
  ["line":protected]=&gt;
  int(1519)
  ["trace":"Exception":private]=&gt;
  array(23) {
    [0]=&gt;
    array(6) {
      ["file"]=&gt;
      string(86) "/var/www/html/intranet/logiciel-codeigniter-dev/vendor/spipu/html2pdf/src/Html2Pdf.php"
      ["line"]=&gt;
      int(5769)
      ["function"]=&gt;
      string(10) "_drawImage"
      ["class"]=&gt;
      string(23) "Spipu\Html2Pdf\Html2Pdf"
      ["type"]=&gt;
      string(2) "-&gt;"
      ["args"]=&gt;
      array(2) {
        [0]=&gt;
        string(0) ""
        [1]=&gt;
        bool(false)
      }
    }
    [1]=&gt;
    array(6) {
      ["file"]=&gt;
      string(86) "/var/www/html/intranet/logiciel-codeigniter-dev/vendor/spipu/html2pdf/src/Html2Pdf.php"
      ["line"]=&gt;
      int(1439)
      ["function"]=&gt;
      string(13) "_tag_open_IMG"
      ["class"]=&gt;
      string(23) "Spipu\Html2Pdf\Html2Pdf"
      ["type"]=&gt;
      string(2) "-&gt;"
      ["args"]=&gt;
      array(1) {
        [0]=&gt;
        array(4) {
          ["style"]=&gt;
          array(1) {
            ["width"]=&gt;
            string(3) "68%"
          }
          ["alt"]=&gt;
          string(0) ""
          ["src"]=&gt;
          string(0) ""
          ["num"]=&gt;
          int(14)
        }
      }
    }
    [2]=&gt;
    array(6) {
      ["file"]=&gt;
      string(86) "/var/www/html/intranet/logiciel-codeigniter-dev/vendor/spipu/html2pdf/src/Html2Pdf.php"
      ["line"]=&gt;
      int(1407)
      ["function"]=&gt;
      string(14) "_executeAction"
      ["class"]=&gt;
      string(23) "Spipu\Html2Pdf\Html2Pdf"
      ["type"]=&gt;
      string(2) "-&gt;"
      ["args"]=&gt;
      array(1) {
        [0]=&gt;
        object(Spipu\Html2Pdf\Parsing\Node)#838 (5) {
          ["name":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          string(3) "img"
          ["params":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          array(4) {
            ["style"]=&gt;
            array(1) {
              ["width"]=&gt;
              string(3) "68%"
            }
            ["alt"]=&gt;
            string(0) ""
            ["src"]=&gt;
            string(0) ""
            ["num"]=&gt;
            int(14)
          }
          ["close":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          bool(false)
          ["autoClose":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          bool(true)
          ["line":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          int(177)
        }
      }
    }
    [3]=&gt;
    array(6) {
      ["file"]=&gt;
      string(86) "/var/www/html/intranet/logiciel-codeigniter-dev/vendor/spipu/html2pdf/src/Html2Pdf.php"
      ["line"]=&gt;
      int(5589)
      ["function"]=&gt;
      string(13) "_makeHTMLcode"
      ["class"]=&gt;
      string(23) "Spipu\Html2Pdf\Html2Pdf"
      ["type"]=&gt;
      string(2) "-&gt;"
      ["args"]=&gt;
      array(0) {
      }
    }
    [4]=&gt;
    array(6) {
      ["file"]=&gt;
      string(86) "/var/www/html/intranet/logiciel-codeigniter-dev/vendor/spipu/html2pdf/src/Html2Pdf.php"
      ["line"]=&gt;
      int(1439)
      ["function"]=&gt;
      string(12) "_tag_open_TD"
      ["class"]=&gt;
      string(23) "Spipu\Html2Pdf\Html2Pdf"
      ["type"]=&gt;
      string(2) "-&gt;"
      ["args"]=&gt;
      array(1) {
        [0]=&gt;
        array(4) {
          ["style"]=&gt;
          array(4) {
            ["width"]=&gt;
            string(3) "15%"
            ["vertical-align"]=&gt;
            string(6) "middle"
            ["padding-middle"]=&gt;
            string(3) "5px"
            ["text-align"]=&gt;
            string(6) "center"
          }
          ["num"]=&gt;
          int(14)
          ["cellpadding"]=&gt;
          string(18) "0.26458333333333mm"
          ["cellspacing"]=&gt;
          string(18) "0.52916666666667mm"
        }
      }
    }
    [5]=&gt;
    array(6) {
      ["file"]=&gt;
      string(86) "/var/www/html/intranet/logiciel-codeigniter-dev/vendor/spipu/html2pdf/src/Html2Pdf.php"
      ["line"]=&gt;
      int(1393)
      ["function"]=&gt;
      string(14) "_executeAction"
      ["class"]=&gt;
      string(23) "Spipu\Html2Pdf\Html2Pdf"
      ["type"]=&gt;
      string(2) "-&gt;"
      ["args"]=&gt;
      array(1) {
        [0]=&gt;
        object(Spipu\Html2Pdf\Parsing\Node)#836 (5) {
          ["name":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          string(2) "td"
          ["params":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          array(2) {
            ["style"]=&gt;
            array(4) {
              ["width"]=&gt;
              string(3) "15%"
              ["vertical-align"]=&gt;
              string(6) "middle"
              ["padding-middle"]=&gt;
              string(3) "5px"
              ["text-align"]=&gt;
              string(6) "center"
            }
            ["num"]=&gt;
            int(14)
          }
          ["close":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          bool(false)
          ["autoClose":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          bool(false)
          ["line":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          int(176)
        }
      }
    }
    [6]=&gt;
    array(6) {
      ["file"]=&gt;
      string(86) "/var/www/html/intranet/logiciel-codeigniter-dev/vendor/spipu/html2pdf/src/Html2Pdf.php"
      ["line"]=&gt;
      int(3123)
      ["function"]=&gt;
      string(13) "_makeHTMLcode"
      ["class"]=&gt;
      string(23) "Spipu\Html2Pdf\Html2Pdf"
      ["type"]=&gt;
      string(2) "-&gt;"
      ["args"]=&gt;
      array(0) {
      }
    }
    [7]=&gt;
    array(6) {
      ["file"]=&gt;
      string(86) "/var/www/html/intranet/logiciel-codeigniter-dev/vendor/spipu/html2pdf/src/Html2Pdf.php"
      ["line"]=&gt;
      int(1439)
      ["function"]=&gt;
      string(13) "_tag_open_DIV"
      ["class"]=&gt;
      string(23) "Spipu\Html2Pdf\Html2Pdf"
      ["type"]=&gt;
      string(2) "-&gt;"
      ["args"]=&gt;
      array(1) {
        [0]=&gt;
        array(2) {
          ["style"]=&gt;
          array(1) {
            ["border-top"]=&gt;
            string(14) "1px solid #ccc"
          }
          ["num"]=&gt;
          int(0)
        }
      }
    }
    [8]=&gt;
    array(6) {
      ["file"]=&gt;
      string(86) "/var/www/html/intranet/logiciel-codeigniter-dev/vendor/spipu/html2pdf/src/Html2Pdf.php"
      ["line"]=&gt;
      int(1407)
      ["function"]=&gt;
      string(14) "_executeAction"
      ["class"]=&gt;
      string(23) "Spipu\Html2Pdf\Html2Pdf"
      ["type"]=&gt;
      string(2) "-&gt;"
      ["args"]=&gt;
      array(1) {
        [0]=&gt;
        object(Spipu\Html2Pdf\Parsing\Node)#824 (5) {
          ["name":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          string(3) "div"
          ["params":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          array(2) {
            ["style"]=&gt;
            array(1) {
              ["border-top"]=&gt;
              string(14) "1px solid #ccc"
            }
            ["num"]=&gt;
            int(0)
          }
          ["close":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          bool(false)
          ["autoClose":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          bool(false)
          ["line":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          int(170)
        }
      }
    }
    [9]=&gt;
    array(6) {
      ["file"]=&gt;
      string(86) "/var/www/html/intranet/logiciel-codeigniter-dev/vendor/spipu/html2pdf/src/Html2Pdf.php"
      ["line"]=&gt;
      int(2971)
      ["function"]=&gt;
      string(13) "_makeHTMLcode"
      ["class"]=&gt;
      string(23) "Spipu\Html2Pdf\Html2Pdf"
      ["type"]=&gt;
      string(2) "-&gt;"
      ["args"]=&gt;
      array(0) {
      }
    }
    [10]=&gt;
    array(6) {
      ["file"]=&gt;
      string(86) "/var/www/html/intranet/logiciel-codeigniter-dev/vendor/spipu/html2pdf/src/Html2Pdf.php"
      ["line"]=&gt;
      int(1439)
      ["function"]=&gt;
      string(25) "_tag_open_PAGE_FOOTER_SUB"
      ["class"]=&gt;
      string(23) "Spipu\Html2Pdf\Html2Pdf"
      ["type"]=&gt;
      string(2) "-&gt;"
      ["args"]=&gt;
      array(1) {
        [0]=&gt;
        array(2) {
          ["style"]=&gt;
          array(0) {
          }
          ["num"]=&gt;
          int(0)
        }
      }
    }
    [11]=&gt;
    array(6) {
      ["file"]=&gt;
      string(86) "/var/www/html/intranet/logiciel-codeigniter-dev/vendor/spipu/html2pdf/src/Html2Pdf.php"
      ["line"]=&gt;
      int(1407)
      ["function"]=&gt;
      string(14) "_executeAction"
      ["class"]=&gt;
      string(23) "Spipu\Html2Pdf\Html2Pdf"
      ["type"]=&gt;
      string(2) "-&gt;"
      ["args"]=&gt;
      array(1) {
        [0]=&gt;
        object(Spipu\Html2Pdf\Parsing\Node)#822 (5) {
          ["name":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          string(15) "page_footer_sub"
          ["params":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          array(2) {
            ["style"]=&gt;
            array(0) {
            }
            ["num"]=&gt;
            int(0)
          }
          ["close":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          bool(false)
          ["autoClose":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          bool(false)
          ["line":"Spipu\Html2Pdf\Parsing\Node":private]=&gt;
          int(169)
        }
      }
    }
    [12]=&gt;
    array(6) {
      ["file"]=&gt;
      string(86) "/var/www/html/intranet/logiciel-codeigniter-dev/vendor/spipu/html2pdf/src/Html2Pdf.php"
      ["line"]=&gt;
      int(988)
      ["function"]=&gt;
      string(13) "_makeHTMLcode"
      ["class"]=&gt;
      string(23) "Spipu\Html2Pdf\Html2Pdf"
      ["type"]=&gt;
      string(2) "-&gt;"
      ["args"]=&gt;
      array(0) {
      }
    }
    [13]=&gt;
    array(6) {
      ["file"]=&gt;
      string(86) "/var/www/html/intranet/logiciel-codeigniter-dev/vendor/spipu/html2pdf/src/Html2Pdf.php"
      ["line"]=&gt;
      int(2844)
      ["function"]=&gt;
      string(14) "_setPageFooter"
      ["class"]=&gt;
      string(23) "Spipu\Html2Pdf\Html2Pdf"
      ["type"]=&gt;
      string(2) "-&gt;"
      ["args"]=&gt;
      array(0) {
      }
    }
    [14]=&gt;
    array(6) {
      ["file"]=&gt;
      string(86) "/var…

<page format="A4" backtop="0mm" backbottom="00mm" backleft="0mm" backright="0mm" orientation="portrait" backimg="/var/www/html/images/icon-desc/bg-label.jpg" backimgy="bottom" backimgx="left" backimgw="50%">

And i call Html2Pdf with

$html2pdfprivate = new Html2Pdf('P', $format, 'fr');
$html2pdfprivate->pdf->SetDisplayMode('fullpage');
$html2pdfprivate->writeHTML($contentprivate, false);
$html2pdfprivate->output($pathFileBien . $file, 'F');

Mahdjou avatar Oct 19 '21 11:10 Mahdjou