简体   繁体   中英

run file pdf without popup download laravel

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.

弹出窗口

/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.

Chrome在此处输入图像描述

Edge在此处输入图像描述

Firefox 在此处输入图像描述

Pale Moon secured with no JavaScript allowed在此处输入图像描述

Correcting web spelling inline before print

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM