1

I am having an issue with DOMPDF image loading. I tried all the way to load the image but it won't work on my local / server. isRemoteEnabled mode changed to true. I wanted to load a PNG image. Please help me if you have an idea of how to resolve this issue. I really appreciate any help you can provide. When i try this code am getting mem

Constructor:

  $options = new Options();
  $options->set('defaultFont', 'Helvetica');
  $options->set('isRemoteEnabled', TRUE);
  $options->set('debugKeepTemp', true);
  $options->set('isHtml5ParserEnabled', true);
  $this->dompdf = new Dompdf($options);

Fucntion :

    $path = '../logo.png'; 
    $type = pathinfo($path, PATHINFO_EXTENSION); 
    $data = file_get_contents($path); 
    $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);

    #data
    $data = array_merge($this->data, [
        'title' => $this->title,
        'word' => $this->word,
        'breadcrumb' => array("0" => array("url" => base_url("home"), "title" => 'Home'), "1" => array("url" => $url,
            "title" => $this->word_multi)),
        'action' => $url,
        'customerID' => $cid,
        'siteID' => $site,
        'contractRow' => $contractRow,
        'base64' => $base64

    ]);     

    #Contract file name  
    $contract = str_replace('/', "-", $contractRow['contractNumber']);        
    #remove UTF8 issue header     
    $this->response->removeHeader('Content-Type');     
    #viewpage data
    $this->dompdf->loadHtml(view($this->path_views . 'contract', $data));
    $this->dompdf->set_option('defaultMediaType', 'all');    
    $this->dompdf->setPaper('A4','portrait');
    $this->dompdf->render(); 
   
    $this->dompdf->stream( $contract, array("Attachment" => false));

View

 <td width="20%"> <img src="<?php echo $base64; ?>" /></td>

Error which is getting. My memory limit is 512M

ash
  • 21
  • 1
  • 1
    Seems your image is bigger than the PHP allowed size. Test with a very small image first and see if it works, if that works simply increase the size of PHP memory size. – Dhaval Chheda Jul 18 '22 at 09:59
  • What do you get when you run [`filesize($path)`](https://www.php.net/manual/en/function.filesize.php)? – steven7mwesigwa Jul 19 '22 at 09:37
  • [Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted](https://stackoverflow.com/questions/561066/fatal-error-allowed-memory-size-of-134217728-bytes-exhausted-codeigniter-xml) – steven7mwesigwa Jul 19 '22 at 09:46
  • [Allowed memory size of 33554432 bytes exhausted (tried to allocate 43148176 bytes) in php](https://stackoverflow.com/questions/415801/allowed-memory-size-of-33554432-bytes-exhausted-tried-to-allocate-43148176-byte) – steven7mwesigwa Jul 19 '22 at 09:47

0 Answers0