phpimagetcpdfhtml2pdf

How to fix: Unable to get the size of the image [] with HTML2PDF


I check other similar posts where people have the same issue but none of them were of help.

What I tried is to swap this 3 ways of path but I get same error message with all of them:

$logo = 'assets/company/logo-png-3.png';
$logo1 = 'https://my.hostname.co.uk/assets/company/logo-png-3.png';
$logo2 = '/home/username/my.hostname.co.uk/assets/company/logo-png-3.png';


$html = '<div>';
$html .= '<img src="'.$logo.'">';
$html .= '</div>';


  $html2pdf = new HTML2PDF('P', 'A4', 'en', 'UTF-8');
  $html2pdf->writeHTML($html);
  $html2pdf->output($file, 'F');

Also I set in my project directory php.ini file that includes:

allow_url_fopen = On;
allow_url_include = On;

But I am still getting:

Unable to get the size of the image [] with HTML2PDF


Solution

  • Problem solved

    For some reason in vendor\spipu\html2pdf\src\Html2Pdf.php

    protected function _tag_open_IMG($param)
    {
    
      print_r($param);
    
        $src    = str_replace('&amp;', '&', $param['src']);
    

    im getting result like this

    Array ( 
    [style] => Array ( ) 
    [alt] => 
    [src] => 
    [href] => https://my.hostname.co.uk/assets/company/logo-png-3.png
    [num] => 1 
    ) 
    

    so i just change

    $src    = str_replace('&amp;', '&', $param['src']);
    

    to

    $src    = str_replace('&amp;', '&', $param['href']);