Skip to content

Running out of memory in tcpdi_parser #29

@Marchiuzzz

Description

@Marchiuzzz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions