protonemedia/laravel-splade

error when exporting as pdf

wissindrako opened this issue · 8 comments

  • Laravel Version: 9.19

  • PHP Version: 8.0.2

  • Splade PHP Version (composer): 1.4.3

Error when exporting to pdf using dompdf package "barryvdh/laravel-dompdf": "^1.0"

Description:

The error occurs when trying any of the basic ways to create a PDF;

use Barryvdh\DomPDF\Facade\Pdf;

$pdf = Pdf::loadView('pdf.invoice', $data);
return $pdf->download('invoice.pdf');

or

$pdf = App::make('dompdf.wrapper');
$pdf->loadHTML('<h1>Test</h1>');
return $pdf->stream();

showing the following message: "An error occurred while loading the PDF document."

Same problem.. cant make it work

Found an solution.. remove the route from the middleware of Splade

Thanks hipoagencia, for now I solved removing the middleware with "withoutMiddleware"

        Route::withoutMiddleware('splade')->group(function () {
            Route::get('/invoice/{id}', [InvoiceController::class, 'show'])->name('invoice.show'); // My PDF Controller
        });

Are you using a <Link> attribute or a regular <a> attribute?

I'm using the regular <a> attribute to be able to generate the pdf in a new window with target="_blank", and the <Link> attribute also gave me the following error in console: The response is not a Splade response. Did you use the Splade Middleware on this route?

Working on a fix!

Thank you very much, stay tuned!

Fixed in v1.4.7, make sure to update both packages (JS + PHP).