wemersonjanuario / laravelpdf
适用于Laravel的另一个HTML到PDF转换器
1.1.1
2017-03-30 13:27 UTC
Requires
- php: >=5.4.0
- illuminate/http: 5.x
- illuminate/view: 5.x
- wemersonjanuario/pdf: 1.x
Suggests
This package is not auto-updated.
Last update: 2024-09-11 15:25:36 UTC
README
这是一个为Laravel 5提供的另一个HTML到PDF转换器(有关Laravel 4的说明,请见cangelis/l4pdf)。此包使用wkhtmltopdf作为第三方工具,因此必须在您的PHP配置中启用proc_*()
函数,并且应在您的机器上安装wkhtmltopdf
工具(您可以从此处下载)。
如果您不是Laravel用户,请查看这里
安装
步骤 1
将此添加到您的composer.json
{
"require": {
"wemersonjanuario/laravelpdf": "1.1.*"
}
}
步骤 2
将此行添加到您的config/app.php
中的providers
数组
Novanti\LaravelPDF\PDFServiceProvider::class
步骤 3
将此行添加到您的config/app.php
中的aliases
数组
'PDF' => Novanti\LaravelPDF\PDFFacade::class,
步骤 4
运行此命令以发布此包的配置
php artisan vendor:publish
步骤 5
在config/laravelpdf.php
下配置您的wkhtmltopdf
可执行路径
'executable' => '/usr/bin/wkhtmltopdf'
一些示例
PDF::loadView('pdf.invoice')->download('invoice.pdf');
PDF::loadURL('http://www.laravel.com')->grayscale()->pageSize('A3')->orientation('Landscape')->stream('laravel.pdf')
Route::get('/', function() {
return PDF::loadHTML('<strong>Hello World</strong>')->lowquality()->pageSize('A2')->download();
});
Since 1.0.3 the library supports generating PDF from multiple Laravel views of HTML pieces. Each part begins from a new page. Examples of using this feature:
PDF::loadViews(['pdf.order', 'pdf.invoice', 'pdf.wiretransfer'])->download('payment-bundle.pdf');
$htmlPages[] = getMainReport();
$htmlPages[] = getAdditionalReport();
PDF::loadHTMLs($htmlPages)->download('consolidated-report.pdf');
## 保存PDF
laravelpdf使用League\Flysystem将文件保存到本地或远程文件系统。
用法
$pdfObject->save(string $filename, League\Flysystem\AdapterInterface $adapter, $overwrite)
filename
: 要保存的文件名
adapter
: FlySystem适配器
overwrite
: 如果设置为true
并且文件已存在,则将其覆盖,否则将抛出异常。
示例
// Save the pdf to the local file system
PDF::loadHTML('<b>Hello World</b>')
->save("invoice.pdf", new League\Flysystem\Adapter\Local(__DIR__.'/path/to/root'));
// Save to AWS S3
$client = S3Client::factory([
'key' => '[your key]',
'secret' => '[your secret]',
]);
PDF::loadHTML('<b>Hello World</b>')
->save("invoice.pdf", new League\Flysystem\Adapter\AwsS3($client, 'bucket-name', 'optional-prefix'));
// Save to FTP
$ftpConf = [
'host' => 'ftp.example.com',
'username' => 'username',
'password' => 'password',
/** optional config settings */
'port' => 21,
'root' => '/path/to/root',
'passive' => true,
'ssl' => true,
'timeout' => 30,
];
PDF::loadHTML('<b>Hello World</b>')
->save("invoice.pdf", new League\Flysystem\Adapter\Ftp($ftpConf));
// Save to the multiple locations and stream it
return PDF::loadHTML('<b>Hello World</b>')
->save("invoice.pdf", new League\Flysystem\Adapter\Ftp($ftpConf))
->save("invoice.pdf", new League\Flysystem\Adapter\AwsS3($client, 'bucket-name', 'optional-prefix'))
->save("invoice.pdf", new League\Flysystem\Adapter\Local(__DIR__.'/path/to/root'))
->download();
请参阅League\Flysystem的文档中所有可用的适配器
文档
您可以在完整的文档文件中查看所有可用的方法
贡献
请随意贡献!
谢谢
感谢Can Geliş,他为Laravel 4提供了支持cangelis/l4pdf