0

Hi I am trying to implement a pdf file feature on codeigniter 4 using Dompdf but am getting an error: Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 262148096 bytes)

I am working on my localhost, have tried to increase the memory limit to a larger size but the page keeps loading and never stops. This is only when I try to embed an image in the code like so:


      $dompdf = new \Dompdf\Dompdf();

      $image=file_get_contents(ROOTPATH."/public/img/ss_logo_bgwhite.png");
      $imagedata=base64_encode($image);
      $imgpath = '<img src="data:image/png;base64, '.$imagedata.'">';
    

      $HTML='<body><div>'.$imgpath.'</div></body>';
      $document_title = "Quote#$quoteId";


      $options = $dompdf->getOptions();
      $options->setDefaultFont('Helvetica');
      $options->set('dpi','120');
      $options->set('isRemoteEnabled', TRUE);
      // $options->set('isPhpEnabled ', true);
      $options->set('isHtml5ParserEnabled',true);
      $options->set('tempDir', ROOTPATH.'/public/uploads/');
      $dompdf->setOptions($options);
      $dompdf->loadHtml($HTML);
      $dompdf->setPaper('A4', 'landscape');
      $dompdf->render();
      $dompdf->stream($document_title, ["compress" => 1, "Attachment" => false]);

I think it a problem with the Dompdf library has anyone come across this issue?

Similar issue: Codeigniter 4 DOMPDF (2.0.0) PNG Image loading issue . PHP version 8.0.17

bStaq
  • 121
  • 1
  • 2
  • 7
  • 1
    Which version of CI are you using? In the last one (4.3.2), they have fixed their Exception page to display the appropriate error and not the memory leak useless message. Here is the issue fixed: https://github.com/codeigniter4/CodeIgniter4/pull/7212. You can find a workaround here if you don’t want to update your CI version to 4.3.2. https://forum.codeigniter.com/showthread.php?tid=86536 – b126 Mar 11 '23 at 22:38

1 Answers1

0

I am using CI version 4.3.1 I used the 'workaround' fix and got a proper error message from Dompdf. It turned out that I was missing a PHP GD extension, I just had to edit my php.ini to include 'extension=gd' line. This error was driving me nuts, thank you @b126.

bStaq
  • 121
  • 1
  • 2
  • 7