igormatkovic / pdf-l4 by igormatkovic
forked from thujohn/pdf-l4

dompdf for Laravel 4
16
1
1
Package Data
Maintainer Username: igormatkovic
Maintainer Contact: jonathan.thuau@gmail.com (thujohn)
Package Create Date: 2014-09-22
Package Last Update: 2014-09-22
Language: PHP
License: MIT
Last Refreshed: 2024-11-19 03:23:29
Package Statistics
Total Downloads: 16
Monthly Downloads: 1
Daily Downloads: 0
Total Stars: 1
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

Dompdf

Simple Dompdf package for Laravel 4 This package uses the latest stable version (0.5)

Build Status

Installation

Add thujohn/pdf to composer.json.

"thujohn/pdf": "dev-master"

Run composer update to pull down the latest version of Pdf.

Now open up app/config/app.php and add the service provider to your providers array.

'providers' => array(
	'Thujohn\Pdf\PdfServiceProvider',
)

Now add the alias.

'aliases' => array(
	'PDF' => 'Thujohn\Pdf\PdfFacade',
)

Publish the config

php artisan config:publish thujohn/pdf

Usage

Show a PDF

Route::get('/', function()
{
	$html = '<html><body>'
			. '<p>Put your html here, or generate it with your favourite '
			. 'templating system.</p>'
			. '</body></html>';
	return PDF::load($html, 'A4', 'portrait')->show();
});

Download a PDF

Route::get('/', function()
{
	$html = '<html><body>'
			. '<p>Put your html here, or generate it with your favourite '
			. 'templating system.</p>'
			. '</body></html>';
	return PDF::load($html, 'A4', 'portrait')->download('my_pdf');
});

Returns a PDF as a string

Route::get('/', function()
{
	$html = '<html><body>'
			. '<p>Put your html here, or generate it with your favourite '
			. 'templating system.</p>'
			. '</body></html>';
	$pdf = PDF::load($html, 'A4', 'portrait')->output();
});

Multiple PDFs

for ($i=1;$i<=2;$i++)
{
	$pdf = new \Thujohn\Pdf\Pdf();
	$content = $pdf->load(View::make('pdf.image'))->output();
	File::put(public_path('test'.$i.'.pdf'), $content);
}
PDF::clear();

Examples

Save the PDF to a file in a specific folder, and then mail it as attachement. By @w0rldart

define('BUDGETS_DIR', public_path('uploads/budgets')); // I define this in a constants.php file

if (!is_dir(BUDGETS_DIR)){
	mkdir(BUDGETS_DIR, 0755, true);
}

$outputName = str_random(10); // str_random is a [Laravel helper](http://laravel.com/docs/helpers#strings)
$pdfPath = BUDGETS_DIR.'/'.$outputName.'.pdf';
File::put($pdfPath, PDF::load($view, 'A4', 'portrait')->output());

Mail::send('emails.pdf', $data, function($message) use ($pdfPath){
	$message->from('us@example.com', 'Laravel');
	$message->to('you@example.com');
	$message->attach($pdfPath);
});