Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomly broken PDF's within batch processing #1073

Open
StefanNeuser opened this issue Feb 8, 2025 · 2 comments
Open

Randomly broken PDF's within batch processing #1073

StefanNeuser opened this issue Feb 8, 2025 · 2 comments

Comments

@StefanNeuser
Copy link

StefanNeuser commented Feb 8, 2025

Describe the bug
As soon as we generate more than 1000 PDFs by using PDF::loadView, it starts randomly breaking the PDF design (starts overlapping)

To Reproduce
Steps to reproduce the behavior:

  • Laravel 10 and Package Version v2.2.0
return Pdf::loadView($invoice->templateView(), [
    'invoice' => $invoice,
    'shop' => $invoice->shop,
    'withoutLogo' => $this->withoutLogo,
    'template' => $invoice->templateData($invoice->order),
]);

Expected behavior (works for the i.e. first 1000 pdfs)
Image

Issue
Image

Additional context
When a create i.e. 1000 PDF's with php artisan queue:work --queue=export **--max-jobs=1** --memory=4000 --timeout=3600 step by step (process for process) it's working fine. Without --max-jobs=1 the same issue appears. Same issue when we process the jobs with horizon with a job chunk size of 1000

$jobs = [];
foreach ($this->invoices()->chunk(1000) as $invoiceIds)
{
    $jobs[] = new ExportInvoicesChunkJob($this->shop, $invoiceIds->values());
}

if (empty($jobs))
{
    logger("no invoices for export available");
    return;
}

// zipped und schreibt den export eintrag in die datenbank
$jobs[] = new ExportInvoicesFinishJob($this->shop, $this->params['range']);

Bus::chain($jobs)->catch(function (Throwable $e)
{
    logger($e->getMessage());
})->onQueue('export')->dispatch();

I guess it has something todo with Laravel view / caching system. Maybe the cache but i already tries to drop the cache each 100 PDF's.

We appreciate any help 🙏

@bsweeney
Copy link

bsweeney commented Feb 9, 2025

This could have something to do with a kludge that was put in place to prevent infinite loops (see https://github.com/dompdf/dompdf/blob/v3.1.0/src/LineBox.php#L157).

At some point for a near-term release of Dompdf, I plan to review static usage since there are a few places where static values can be problematic.

@StefanNeuser
Copy link
Author

StefanNeuser commented Feb 10, 2025

Hi @bsweeney , thank you very much for that interesting hint! Do you have any idea how to change it for a test? My thoughts was to move the method prop

static $anti_infinite_loop = 10000; // FIXME smelly hack

to a static class property and reset it as soon a we render a new PDF here

public function output(array $options = []): string
{
    if (!$this->rendered) {
        $this->render();
    }

\Dompdf\LineBox::$anti_infinite_loop = 10000;
    
return (string) $this->dompdf->output($options);
}

EDIT: With that (Hack) it's working now.

Image Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants