barryvdh / laravel-dompdf

A DOMPDF Wrapper for Laravel
MIT License
6.7k stars 966 forks source link

Error 503. Service Unavailable #1022

Closed jleira closed 9 months ago

jleira commented 9 months ago

When attempting to create a PDF from an HTML source, an error 503 is encountered. The following is my code:

$pdf = PDF::loadHtml($html); $pdf->setPaper('A4', 'landscape'); return $pdf->download('offer-gss-' . $id . '.pdf');

Expected behavior "I used to receive a PDF file, which I downloaded on the front end.

Screenshots

Captura de pantalla 2023-12-22 a la(s) 11 59 22 a  m
sajjad-mascot commented 9 months ago

I also facing the same issue, before 2 days ago, it works fine before that for the last 2 years, after troubleshooting the problem, found that the render(); did not work

` $html = ob_get_clean(); // instantiate and use the dompdf class $dompdf = new Dompdf(); define("DOMPDF_ENABLE_REMOTE", false); $dompdf->set_paper(array(0,0,136.6,800));

$GLOBALS['bodyHeight'] = 0;

$dompdf->setCallbacks(
    array(
        'myCallbacks' => array(
            'event' => 'end_frame', 'f' => function ($infos) {
                $frame = $infos["frame"];
                if (strtolower($frame->get_node()->nodeName) === "body") {
                    $padding_box = $frame->get_padding_box();
                    $GLOBALS['bodyHeight'] += $padding_box['h'];
                }
            }
        )
    )
);

$dompdf->loadHtml($html);
$dompdf->render();
unset($dompdf);

$dompdf = new Dompdf();
$dompdf->set_paper(array(0,0,136.6,$GLOBALS['bodyHeight']+10));
$dompdf->loadHtml($html);
$dompdf->render();
$output = $dompdf->output();
$im = new imagick();
$im->setResolution(300, 300);
$im->readImageBlob($output);
$im->setImageFormat('jpg');
$im->setImageCompression(Imagick::COMPRESSION_JPEG);
$im->setCompressionQuality(100);
header("Content-type: image/jpeg");
header("Cache-Control: no-store, no-cache");
header('Content-Disposition: attachment; filename="'.$filename.'.jpg"');`

image

losbit commented 9 months ago

When attempting to create a PDF from an HTML source, an error 503 is encountered. The following is my code:

$pdf = PDF::loadHtml($html); $pdf->setPaper('A4', 'landscape'); return $pdf->download('offer-gss-' . $id . '.pdf');

Expected behavior "I used to receive a PDF file, which I downloaded on the front end.

Screenshots Captura de pantalla 2023-12-22 a la(s) 11 59 22 a  m

How did you solve the issue?

losbit commented 9 months ago

I have the same problem, but do not know how to solve it, why did you close it?

sajjad-mascot commented 9 months ago

The issue was automatically resolved after a few days. I believe it was related to a server resources problem in my case; the disk space on my server was full. Consequently, I resolved the issue by cleaning up the disk space and deleting unnecessary files. It is now functioning properly.