在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):niklasravnsborg/laravel-pdf开源软件地址(OpenSource Url):https://github.com/niklasravnsborg/laravel-pdf开源编程语言(OpenSource Language):PHP 67.6%开源软件介绍(OpenSource Introduction):Laravel PDF: mPDF wrapper for Laravel 5
InstallationRequire this package in your
To start using Laravel, add the Service Provider and the Facade to your 'providers' => [
// ...
niklasravnsborg\LaravelPdf\PdfServiceProvider::class
] 'aliases' => [
// ...
'PDF' => niklasravnsborg\LaravelPdf\Facades\Pdf::class
] Now, you should publish package's config file to your config directory by using following command:
Basic UsageTo use Laravel PDF add something like this to one of your controllers. You can pass data to a view in use PDF;
function generate_pdf() {
$data = [
'foo' => 'bar'
];
$pdf = PDF::loadView('pdf.document', $data);
return $pdf->stream('document.pdf');
} Other methodsIt is also possible to use the following methods on the
ConfigIf you have published config file, you can change the default settings in return [
'format' => 'A4', // See https://mpdf.github.io/paging/page-size-orientation.html
'author' => 'John Doe',
'subject' => 'This Document will explain the whole universe.',
'keywords' => 'PDF, Laravel, Package, Peace', // Separate values with comma
'creator' => 'Laravel Pdf',
'display_mode' => 'fullpage'
]; To override this configuration on a per-file basis use the fourth parameter of the initializing call like this: PDF::loadView('pdf', $data, [], [
'format' => 'A5-L'
])->save($pdfFilePath); You can use a callback with the key 'instanceConfigurator' to access mpdf functions: $config = ['instanceConfigurator' => function($mpdf) {
$mpdf->SetImportUse();
$mpdf->SetDocTemplate(/path/example.pdf, true);
}]
PDF::loadView('pdf', $data, [], $config)->save($pdfFilePath); Headers and FootersIf you want to have headers and footers that appear on every page, add them to your <htmlpageheader name="page-header">
Your Header Content
</htmlpageheader>
<htmlpagefooter name="page-footer">
Your Footer Content
</htmlpagefooter> Now you just need to define them with the name attribute in your CSS: @page {
header: page-header;
footer: page-footer;
} Inside of headers and footers Included FontsBy default you can use all the fonts shipped with mPDF. Custom FontsYou can use your own fonts in the generated PDFs. The TTF files have to be located in one folder, e.g. return [
// ...
'font_path' => base_path('resources/fonts/'),
'font_data' => [
'examplefont' => [
'R' => 'ExampleFont-Regular.ttf', // regular font
'B' => 'ExampleFont-Bold.ttf', // optional: bold font
'I' => 'ExampleFont-Italic.ttf', // optional: italic font
'BI' => 'ExampleFont-Bold-Italic.ttf' // optional: bold-italic font
//'useOTL' => 0xFF, // required for complicated langs like Persian, Arabic and Chinese
//'useKashida' => 75, // required for complicated langs like Persian, Arabic and Chinese
]
// ...add as many as you want.
]
// ...
]; Note: If you are using Now you can use the font in CSS: body {
font-family: 'examplefont', sans-serif;
} Set ProtectionTo set protection, you just call the The passwords are optional. There are a fews permissions: use PDF;
function generate_pdf() {
$data = [
'foo' => 'bar'
];
$pdf = PDF::loadView('pdf.document', $data);
$pdf->SetProtection(['copy', 'print'], '', 'pass');
return $pdf->stream('document.pdf');
} Find more information to TestingTo use the testing suite, you need some extensions and binaries for your local PHP. On macOS, you can install them like this:
LicenseLaravel PDF is open-sourced software licensed under the MIT license |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论