0

I launched the following code and it works fine. The file (http://127.0.0.1:8000/dl/file.pdf) opens as a download pop-up.

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 Laravel - display a PDF file in storage without forcing download?, but it does not work.

I do not want to show pop-up download.

Pedro Rodrigues
  • 637
  • 6
  • 16
itlearn
  • 45
  • 4
  • Does this answer your question? [Laravel - display a PDF file in storage without forcing download?](https://stackoverflow.com/questions/25938294/laravel-display-a-pdf-file-in-storage-without-forcing-download) – CBroe May 16 '22 at 13:29
  • @cboe No. I do not want to show pop-up download. – itlearn May 16 '22 at 13:31
  • That other question is about directly displaying the PDF inside the browser, instead of asking the user where to save it. That _is_ what you want, no ...? – CBroe May 16 '22 at 13:32
  • @cboe I mean open `https://www.itsolutionstuff.com/upload/laravel-8-pdf-ex.pdf` on browser. – itlearn May 16 '22 at 13:36
  • _"but it does not work"_ - and _that_ does not work for us, as a proper problem description. – CBroe May 16 '22 at 13:36
  • @cboe i dont want like this `https://i.stack.imgur.com/Ly77N.png`. – itlearn May 16 '22 at 13:36
  • 2
    Then you will have to tell _your_ browser, that you want to open this directly, instead of storing it somewhere. My browser does not ask me to download `https://www.itsolutionstuff.com/upload/laravel-8-pdf-ex.pdf`, it displays it directly. And your browser is, according to our own screenshot, already asking you what you want to do with this type, and whether you want to do the same thing you choose now, automatically in the future ... – CBroe May 16 '22 at 13:39

1 Answers1

0

Chrome 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

K J
  • 8,045
  • 3
  • 14
  • 36