Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

infernobass7's avatar

DomPDF Causing Bad Gateway

So I am trying to generate a pdf using DomPDF using a view. The PDF should be about one page in length, which I would think would not be that big. However, when I try to run it I get a blank page. The logs have the following message:

 local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message
'Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes)' in /var/www/domain/vendor/dompdf/dompdf/include/cellmap.cls.php:362
0 likes
6 replies
infernobass7's avatar

I found the cause of this issue and when I changed it I run into another issue. In /etc/php5/fpm/php.ini there is a setting for max memory and as a default it is set 128M, which is equal to the large number above. Now the script just sits there doing spinning and I set it to print only a small portion of the entire view.

jasonfrye's avatar

I've used DOMPDF in one of my projects. Can you share the code you're using to render the PDF?

infernobass7's avatar

This is the portion of the HTML that I am trying to use. I have also used a view with this same HTML in it.

$pdf = PDF::loadHTML('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <style>
        .coll_setup{
            width: 0.0568181818181818in;

        }
        td {
            border: 1px solid black;
            border-collapse: collapse;
        }
        table {
            border-collapse: collapse;
            text-align: center;
        }
        div.page{
            width:8.5in;
            height:11in;
            font-size: 10pt;
        }
        div.page_content{
            width:7.5in;
            height:10in;
            margin:auto;
        }
        .data{
            height:2in;
        }
        .left{
            text-align:left;
        }
        tr.noborder td{
            border: none;
        }
        .space{
            height:15px;
        }
    </style>
</head>
<body>
<div class="page">
    <div class="page_content">
        <table>
            <thead>
            <tr>
                <th colspan="132">
                    123 Main Street united States 91209
                </th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
</div>
</body>
</html>');//('documents.pdf');
        return $pdf->save('document.pdf');
jasonfrye's avatar

It's been months since I worked with this package. I seem to remember having trouble saving pdfs as well.

The end of my controller method looks like this:

$pdf = App::make('dompdf');
    $pdf->loadView('admin.reports.pdf', $data)->setPaper('a4')->setOrientation('landscape');
    return $pdf->stream();
infernobass7's avatar

So I did a test this morning and it is appearing that the template that I am using will not work since it uses the head and body tags and uses the styles. If I completely remove the styles it works but otherwise it crashes. Is there some way around this or another laravel package that handles the CSS correctly?

Please or to participate in this conversation.