0 ratings0% found this document useful (0 votes) 259 views6 pagesLaravel pdf2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
@ niklasravnsborg / laravel-pdf (Public
@ Looking for new maintainers, please reach out by opening an issue.
vr 655 stars Y 178 forks
W star
<> Code © Issues 27
11 Pullrequests 13 © Actions
P main ~
© cikasravnstborg Merge pull request #201 from PanovAlexey/main
View code
README.md
watch v
i Projects © Security Lx Insigh
VY ondun8,2021 O56
Laravel PDF: mPDF wrapper for Laravel 5
Easily generate PDF documents from HTML right inside of Laravel using this mPDF
wrapper.
Installation
Require this package in your conposer.json or install it by running:
composer require niklasravnsborg/laravel-pdf
Note: This package supports auto-discovery features of Laravel 5.5+, You only need to
55
manually add the service provider and alias if working on Laravel version lower then
To start using Laravel, add the Service Provider and the Facade to your config/app-php :
"providers*
Moveniklasravnsborg\LaravelPdf\PdfServiceProvider: :class
‘aliases’ => [
We
"POF" => niklasravnsborg\LaravelPdt\Facades\Pdt
lass
Now, you should publish package's config file to your config directory by using following
command:
php artisan vendor: publish
Basic Usage
To use Laravel PDF add something like this to one of your controllers. You can pass data to
a view in /resources/views
use PDF;
function generate_pdf() {
Sdata = [
“foo' => ‘bar’
is
$pdf = POF::loadView('pd#.document’, $data)
return $pdf->stream( ‘document .pdf" )
Other methods
Itis also possible to use the following methods on the pdf object
output() : Outputs the PDF as a string
save($filenane) : Save the PDF to a file
download( $filename) : Make the PDF downloadable by the user.
stream($filenane) : Return a response with the PDF to show in the browser.
ConfigIfyou have published config fi
file:
le, you can change the default settings in config/pdt.php
return [
“Format. AA", // See https://mpdt.github.io/paging/page-size-c
‘author’ "John Doe",
subject" ‘This Document will explain the whole universe. ",
*keywords* "POF, Laravel, Package, Peace’, // Separate values wit
‘creator’ ‘Laravel Pdf"
“display_mode => ‘fullpage
i
To override this configuration on a per-file basis use the fourth parameter of the initializing
call like this:
PDF::loadview(*pdf', $data, [], [
"Format" => "AS-L"
])->save($pdtFilePath) ;
You can use a callback with the key ‘instanceConfigurator' to access mpdf functions:
$config = ["instanceConfigurator’ => function($mpdf) {
$npdf->SetImportUse() 5
$npdf->SetDocTenplate(/path/exanple.pdf, true);
yn
POF:tloadview("pdf', $data, [], Sconfig)->save(SpdfFilePath);
Headers and Footers
Ifyou want to have headers and footers that appear on every page, add them to your
tag like this:
Your Header Content
Your Footer Content
Now you just need to define them with the name attribute in your CSS:
@page {
heade!
Foote!
page-header;
1 page-footer;
Inside of headers and footers {PAGENO} can be used to display the page number.
Included Fonts
By default you can use all the fonts shipped with mPDF.
Custom Fonts
You can use your own fonts in the generated PDFs. The TTF files have to be located in one
folder, e.g. /resources/fonts/ . Add this to your configuration file ( /config/pdf.php )
return [
Wives
“font_path’ => base_path(‘resources/fonts/"),
“font_data’ => [
‘examplefont’ => [
"R' => ‘ExampleFont-Regular.ttf', // regular font
"B' => ‘ExanpleFont-Bold.ttf", // optional: bold font
I’ => ‘ExampleFont-Italic.ttf’, _// optional: italic fc
“BI' => ‘Exanplefont-Bold-Italic.ttf" // optional: bold-ital
//'useOTL' => @xFF, —// required for complicated langs lik
//'usekashida’ => 75, // required for complicated langs ik
// «add as many as you want.
]
Wy.
Lb
Note: If you are using laravel-péf for producing PDF documents in a complicated
language (like Persian, Arabic or Chinese) you should have useoTL and usekashida
indexes in your custom font definition array. If you do not use these indexes, your
characters will be shown dispatched and incorrectly in the produced PDF.
Now you can use the font in CSSbody {
font-family: ‘examplefont', sans-serif;
>
Set Protection
To set protection, you just call the setProtection() method and pass an array with
permissions, an user password and an owner password.
The passwords are optional
There are a fews permissions: ‘copy’, ‘print®, ‘modify’ , ‘annot-forns’, ‘Fi11-
forms’, ‘extract’, ‘assenble’ , ‘print-highres*
use PDFS
function generate_pdf() {
$data = [
“fo0' => ‘bar’
1
$pdf = POF
$pdf->SetProtection([ ‘copy’, ‘print'],
return $pdf->stream('document.pdf");
loadView('pd#.document’, $data);
"', "pass");
Find more information to setProtection() here: https://mpdf github io/reference/mpdf-
functions/setprotection.htm!
Testing
To use the testing suite, you need some extensions and binaries for your local PHP. On
macOS, you can install them like this
brew install imagemagick ghostscript
pecl install imagick
License
Laravel PDF is open-sourced software licensed under the MIT licenseReleases
Qaritags
Used by 21k
CSE GEE
Contributors 1
€O% L034 BOS" 4s
Languages
© PHP 676% © @ HTML 324%