Generate PDF report like (invoice, receipt ) for laravel
- php >= 5.4.0
- Mpdf/Mpdf
- illuminate/support
- illuminate/view
composer require snono/pdf-builder
php artisan vendor:publish
Example Usage: First you need add import class ReportBuilder
use Snono\PDFBuilder\Builder\Classes\PDFBuilder;
see example sample code blow
$invoice = PDFBuilder::make()
->setTemplate('default')
->setData($data)
->show();
to change default configuration of PDFBuilder update file pdf.conf
in config directory of laravel project
Use setTemplate() to set HTML template blade for laravel the default path in resources/view/pdf-builder
$pdf = PDFBuilder::make()
->setTemplate('pdf')
->setData($data)
->show()
Use setCssUrls() to set array of url string to css stylesheet files
$pdf = PDFBuilder::make()
->setCssUrls(array('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'))
->setTemplate('pdf')
->setData($data)
->show()
Use setDirectionality() to ser direction of language take string option ('ltr' OR 'rtl')
$pdf = PDFBuilder::make()
->setCssUrls(array('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'))
->setTemplate('pdf')
->setData($data)
->setDirectionality('rtl')
->show();
Use setFooter() and/or SetHeader() to set header/footer before writing the document ,The text sting defines three stings divided by |
which will set a header at the left/centre/right margin of the page
$pdf = PDFBuilder::make()
->setCssUrls(array('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'))
->setTemplate('pdf')
->setHeader('Document Title')
->setFooter('Document Title|{PAGENO}|{DATE j-m-Y}')
->setData($data)
->setDirectionality('rtl')
->show();
Use setHTMLHeader() and/or setHTMLFooter() to set HTML headers/footers before writing to the document.
void setHTMLHeader ( string $html [, string $side [, boolean $write ]])
void setHTMLFooter ( string $html [, string $side [, boolean $write ]])
$header This parameter specifies the content of the page header as a string of valid HTML code.
Default: BLANK
$side Specify whether to set the header for ODD or EVEN pages in a DOUBLE-SIDED document.
Values (case-sensitive)
'O' - set the header for ODD pages
'E' - set the header for EVEN pages
Default: BLANK, which sets 'O'
$write If true it forces the Header to be written immediately to the current page. Use if the header is being set after the new page has been added.
Default: false
Finalise the document and send it to specified destination , you can use one method below
$pdf->download($filename)
send to the browser and force a file download with the name given by $filename
$pdf->show($filename)
send the file inline to the browser.
$pdf->save( $filename)
save to a local file with the name given by $filename (may include a path).
$result = $pdf->toString()
return the document as a string.