Home > Software engineering >  run file pdf without popup download laravel
run file pdf without popup download laravel

Time:05-18

I launched the following code and it works fine. The file (pop-up

/routes/web.php

<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PDFController;
Route::get('/dl/file.pdf', [PDFController::class, 'generatePDF']);

/app/Http/Controllers/Frontend/PDFController.php

<?php
namespace App\Http\Controllers\Frontend;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use PDF;
class PDFController extends Controller
{
    public function generatePDF()
    {
        $data = [
            'title' => 'Welcome to Laravel',
            'date' => date('m/d/Y')
        ];
        $pdf = PDF::loadView('front.pdf', $data);
        return $pdf->download('laravel.pdf');
    }
}

/front/pdf.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>PDF - Laravel</title>
</head>
<body>
    <h1>{{ $title }}</h1>
    <p>{{ $date }}</p>
    <p>It is a test.</p>
</body>
</html>

I know this code $pdf->download('laravel.pdf') is downloadable.

I read this link enter image description here

Edge enter image description here

Firefox enter image description here

Pale Moon secured with no JavaScript allowed enter image description here

Correcting web spelling inline before print

enter image description here

  • Related