定制 thujohn/pdf 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thujohn/pdf

最新稳定版本:1.0.6

Composer 安装命令:

composer require thujohn/pdf

包简介

dompdf for Laravel 4

README 文档

README

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

Build Status

Installation

Run

composer require thujohn/pdf

OR

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);
});

统计信息

  • 总下载量: 218.43k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 240
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 231
  • Watchers: 15
  • Forks: 76
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-06-22