thujohn/pdf

此包已被弃用且不再维护。作者建议使用 barryvdh/laravel-dompdf 包。

dompdf for Laravel 4

维护者

详细信息

github.com/thujohn/pdf-l4

源代码

问题

安装量: 211 219

依赖者: 1

推荐者: 0

安全: 0

星标: 231

关注者: 15

分支: 76

开放问题: 70

1.0.6 2014-12-02 17:45 UTC

This package is auto-updated.

Last update: 2020-04-27 13:02:59 UTC


README

为Laravel 4提供简单的Dompdf包,本包使用最新稳定版本(0.5)

Build Status

安装

运行

composer require thujohn/pdf

或者

thujohn/pdf 添加到 composer.json

"thujohn/pdf": "dev-master"

运行 composer update 以获取Pdf的最新版本。

现在打开 app/config/app.php 并将服务提供者添加到您的 providers 数组中。

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

现在添加别名。

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

发布配置

php artisan config:publish thujohn/pdf

使用方法

显示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();
});

下载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');
});

返回PDF字符串

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

多个PDF

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

示例

将PDF保存到特定文件夹中的文件,然后作为附件发送邮件。作者:@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](https://laravel.net.cn/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);
});