pdf-l4 icon indicating copy to clipboard operation
pdf-l4 copied to clipboard

Having trouble generating multiple PDFs and adding to zip file

Open paullexen opened this issue 10 years ago • 0 comments

I'm attempting to generate multiple PDFs at a time (in order add them to a zip file for the user to download).

foreach ($items as $item) {
   $html = View::make(Config::get('example.view'), ['item' => $item]);
   $contents[] = PDF::load($html, 'A4', 'portrait')->output();
}

// later on, add each file from $contents to a zip file for download

...and I'm getting the following error on the second time through the loop:

No block-level parent found. Not good.

This is related to #47 and #78, but the solutions posted there don't quite apply to this case because I need to generate multiple PDFs on the same request.

imevul commented on #47 that adding the following line at the beginning of the load() method in the Pdf class fixed the issue:

$this->dompdf = new \DOMPDF();

While this technically works, I would rather not rely on this if possible:

Also, I found that calling PDF::clear, either in the loop or outside of it, did not solve the issue. Any ideas on a fix or workaround?

paullexen avatar Dec 18 '14 14:12 paullexen