pauln / tcpdi_parser

Parser for use with TCPDI, based on TCPDF_PARSER
GNU Lesser General Public License v3.0
27 stars 47 forks source link

Running out of memory in tcpdi_parser #29

Open Marchiuzzz opened 3 years ago

Marchiuzzz commented 3 years ago

I've been using this package for over a year now and suddenly started getting memory exhaustion errors PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in <[...]>/tcpdi_parser.php on line 882 Here's my code

public function downloadFiles($files, $name = 'name.pdf'){
      $pdf = new \TCPDI();
      $pdf->SetPrintHeader(false);
      $pdf->SetPrintFooter(false);
      $filesArr = [];
      $pdf->SetTitle($name);
      foreach($files as $f){
        $filePath = $f->getFirstMedia('pdf')->getFullUrl();
        $width = $f->sheetsize->width;
        $height = $f->sheetsize->height;
        $port_land = ($width > $height) ? "landscape" : "portrait";
        $pdf->AddPage($port_land, array($width, $height));

    $pageCount = $pdf->setSourceFile($filePath);
        for($i = 1; $i <= $pageCount; $i+=1)
        {
          $tplId = $pdf->importPage($i);
          $pdf->useTemplate($tplId, 0, 0, $width);
          if($pageCount > $i){
            $pdf->AddPage();
          }
        }

      }
      $name = str_replace('.pdf', '', $name).'.pdf';
      $pdf->Output($name, "I");
    }

I'm attaching one of the pdfs that causes this error, I'm really lost at where should I even begin to look for the problem. problems.pdf