laravel logo - Create PDF document using Laravel 4

Create PDF document using Laravel 4

Posted on

laravel logo - Create PDF document using Laravel 4

If you are developing a PHP based web application using Laravel and have some requirement to create PDF documents then you have very limited choice. I was searching some php library for generating PDF document and came across Dompdf. It’s a very simple Laravel library which can be used for generating PDF with lots of Options. You can create single or multiple PDF with page size, page orientation and can show / download PDF or return it as String.

First step is to download the Dompdf library. To download the project use one of the two approaches below.

1) Run the following command on your projects base directory.

I ran the above command and got the following output.

Laravel PDF composer - Create PDF document using Laravel 4

2) Edit composer.js file, add thujohn/pdf entry and run composer update to pull down the latest version of Pdf..

Following is my composer.js file I am sharing for your reference.

Second step is to open app.php file available in /app/config/app.php directory and add a new entry in providers array.

Now add the alias.

To test your PDF document, add following code in route.php

Now, we are all set. Open the browser and hit the URL you will see following Output.

laravel pdf download - Create PDF document using Laravel 4

Happy Coding 🙂

Source techzoo.org