You are not logged in.

Important Note: This forum is being archived and will be completely locked down on the 7th of February. The new forum can be found at http://laravel.io.

Announcement

    Laravel 4 Advanced Architecture: Book Now On Sale

#1 2013-05-03 14:07:52

adamck
Artisan
Registered: 2013-01-23
Posts: 31

[EXAMPLE / TUTORIAL] - DOMPDF - HTML -> PDF Generator

Hi All.
As i couldnt find any docs or info regarding PDF generating in L4 i decided to have a bash myself and then write a short guide for people to get started.

Im using the DOMPDF package via packagist - https://packagist.org/packages/dompdf/dompdf

Add DOMPDF to our composer.json

"dompdf/dompdf": "dev-master"

Run 'composer update'

In '../vendor/dompdf/dompdf/dompdf_config.inc.php'

change this to allow remote images to be used in PDF.

def("DOMPDF_ENABLE_REMOTE", false);

to

def("DOMPDF_ENABLE_REMOTE", true);

In your controller

public function getPdf()
	{
               // YOU NEED THIS FILE BEFORE YOU CAN RUN DOMPDF <-- im sure someone has a better way of referencing it for Laravel?
		require_once("../vendor/dompdf/dompdf/dompdf_config.inc.php");
               // You can use raw HTML or a blade template, i made a pdf folder within *views* for my templates.
		$html =  View::make('pdf.sometest'); 

		$dompdf = new DOMPDF();
		$dompdf->load_html($html);
		$dompdf->render();

		// Use this to output to the broswer
		$dompdf->stream('my.pdf',array('Attachment'=>0));
		// Use this to download the file.
		// $dompdf->stream("my.pdf");
	}

I hope this helps someone, if anyone has a better way of referencing/including the config file, please feel free to amend it, im still new to L4.
Adam.

Offline

#2 2013-05-03 14:43:20

Barryvdh
Artisan
From: Eindhoven, Netherlands
Registered: 2012-10-22
Posts: 861
Website

Re: [EXAMPLE / TUTORIAL] - DOMPDF - HTML -> PDF Generator

You could use the real path: base_path()."/vendor/dompdf/dompdf/dompdf_config.inc.php"


Laravel IDE Helper Generator (Generates auto-completion for phpStorm/NetBeans/Sublime CodeIntel)
Laravel PHP Debugbar (Profiler/Web toolbar for Debug/Database/Views and Ajax/Redirect support)

Offline

#3 2013-08-14 11:39:23

carbontwelve
Artisan
Registered: 2013-05-29
Posts: 8

Re: [EXAMPLE / TUTORIAL] - DOMPDF - HTML -> PDF Generator

This is really helpful, im giving it a go now smile

Offline

#4 2013-08-14 12:05:05

Barryvdh
Artisan
From: Eindhoven, Netherlands
Registered: 2012-10-22
Posts: 861
Website

Re: [EXAMPLE / TUTORIAL] - DOMPDF - HTML -> PDF Generator

Here is also a simple wrapper for Laravel: https://github.com/barryvdh/laravel-dompdf


Laravel IDE Helper Generator (Generates auto-completion for phpStorm/NetBeans/Sublime CodeIntel)
Laravel PHP Debugbar (Profiler/Web toolbar for Debug/Database/Views and Ajax/Redirect support)

Offline

#5 2013-08-14 12:18:45

carbontwelve
Artisan
Registered: 2013-05-29
Posts: 8

Re: [EXAMPLE / TUTORIAL] - DOMPDF - HTML -> PDF Generator

Ah that's even better.

Offline

Board footer

Powered by FluxBB

');