How to Display PDF file in Laravel From Public Folder -

Bipsmedium
2 min readMay 23, 2022

In this tutorial, we will learn how to display PDF file in laravel from the public folder. This is a very important feature of web development and is often used in web applications. There are various ways to do this in laravel but I have given the simplest way to return a pdf file and showing on the browser. The functions of showing files on the browser are a little bit different in core PHP. Also, you will learn both ways in this tutorial. Please follow the below steps

Steps to display PDF file in laravel

Step 1:- Locate the PDF document inside the laravel public folder of your project.

Also read, How to create laravel project from scratch step by step

Step 2 :- Set up the route in inside the routes folder of your laravel project as shown below

//for displaying PDF Route::get('/display_pdf','PdfController@index');

Step 3:- Create a controller by using the artisan command as shown below

php artisan make:controller PdfController

PdfController:-

<?php 
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use File;
use Response;
class PdfController extends Controller {
//
public function index(){
return Response::make(file_get_contents('images/image1.pdf'), 200, [ 'content-type'=>'application/pdf', ]);
}
}

Step 4:- Hit the below URL on the browser as shown below

http://127.0.0.1:8000/display_pdf

Now you can see the PDF document as shown below

Also read, How to display PDF file in PHP on browser

Conclusion:- I hope this tutorial will help you to understand the overview. If there is any doubt then please leave a comment below

Originally published at https://pbphpsolutions.com on May 23, 2022.

--

--

Bipsmedium

Hi, This is Biplab and I am a PHP laravel developer and other open source technologies. I am here to share my experience with the community.