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

theharisshah's avatar

Snappy PDF error exit with code 1

Please help me to figure out what could be the issue

    public function generateProformaPdf()
    {
        $bookings = Booking::all();
        $date = Carbon::now()->toDateString();
        foreach($bookings as $booking){
            $filename = $booking->id.'--'.$date.".pdf";
            $invoice = SnappyPdf::loadview('pdf.proforma_invoice', compact('booking'));
            $invoice->save(storage_path("app/public/invoices/proformainvoices/", $filename));
            $proformaInvoice = new ProformaInvoice();
            $proformaInvoice->file = $filename;
            $proformaInvoice->save();
        }
    }

The above function generates following RunTimeException

The exit status code '1' says something went wrong: stderr: "Loading pages (1/6) [> ] 0% [======> ] 10% [==============================> ] 50% [============================================================] 100% QPainter::begin(): Returned false Error: Unable to write to destination Exit with code 1, due to unknown error. " stdout: "" command: /usr/local/bin/wkhtmltopdf --lowquality '/var/tmp/knp_snappy5bbdf5bc3f1978.38608827.html' '/Users/harisshah/Development/postcard/storage/app/public/invoices/proformainvoices/'.

Can't figure out the issue. Only this function gives this exception rest all functions with pdf save and generation work ok.

0 likes
3 replies
D9705996's avatar

Does this folder exist in you filesystem as this is where the output is trying to write to?

/Users/harisshah/Development/postcard/storage/app/public/invoices/proformainvoices/

If it doesn't you need to create it or change the path to somewhere that does exist in this code

storage_path("app/public/invoices/proformainvoices/", $filename));

Bear in mind I doubt you want to put invoices into anything that is public!

1 like
theharisshah's avatar
theharisshah
OP
Best Answer
Level 1

@D9705996 I figured out the error, thanks to you I noticed the silly mistake I had made, it usually creates the path even if it doesn't exist. Although the silly mistake i made I was passing $filename as the second parameter which should have been actually concatenated to the path. Wrong :

storage_path("app/public/invoices/proformainvoices/", $filename));

Right :

storage_path("app/public/invoices/proformainvoices/".$filename));

Please or to participate in this conversation.