All Projects → niklasravnsborg → Laravel Pdf

niklasravnsborg / Laravel Pdf

📄 Easily generate PDF documents from HTML inside of Laravel 5

Projects that are alternatives of or similar to Laravel Pdf

Laravel Pdf
A Simple package for easily generating PDF documents from HTML. This package is specially for laravel but you can use this without laravel.
Stars: ✭ 79 (-85.69%)
Mutual labels:  laravel, pdf-generation
Laravel Fpdf
Create PDFs with Laravel, provides FPDF version 1.82
Stars: ✭ 108 (-80.43%)
Mutual labels:  laravel, pdf-generation
Report
Report management package in PHP that aims to help you export information in a variety of formats
Stars: ✭ 125 (-77.36%)
Mutual labels:  laravel, pdf-generation
Urlhum
The modern, privacy-aware URL Shortener built in PHP.
Stars: ✭ 513 (-7.07%)
Mutual labels:  laravel
Larametrics
A self-hosted metrics and notifications platform for Laravel apps
Stars: ✭ 517 (-6.34%)
Mutual labels:  laravel
Idea Php Laravel Plugin
Laravel Framework Plugin for PhpStorm / IntelliJ IDEA
Stars: ✭ 537 (-2.72%)
Mutual labels:  laravel
Ecjia Daojia
EC+(ecjia)到家是一款可开展O2O业务的移动电商系统。它包含:移动端APP,采用原生模式开发,覆盖使用iOS 及Android系统的移 动终端;后台系统,针对平台日常运营维护的平台后台,针对入驻店铺管理的商家后台,独立并行;移动端H5,能够灵活部署于微信及其他APP、网页等。
Stars: ✭ 547 (-0.91%)
Mutual labels:  laravel
Dusk Dashboard
A beautiful dashboard for your Laravel Dusk tests
Stars: ✭ 507 (-8.15%)
Mutual labels:  laravel
Ecommerce Open Api
果酱小店:基于 Laravel + swoole + 小程序的开源电商系统,优雅与性能兼顾 : )
Stars: ✭ 546 (-1.09%)
Mutual labels:  laravel
Curl
Custom PHP curl library for the Laravel 5 framework - developed by Ixudra
Stars: ✭ 537 (-2.72%)
Mutual labels:  laravel
Compoships
Multi-columns relationships for Laravel's Eloquent ORM
Stars: ✭ 537 (-2.72%)
Mutual labels:  laravel
Laravel Binary Uuid
Optimised binary UUIDs in Laravel
Stars: ✭ 523 (-5.25%)
Mutual labels:  laravel
Laravel Vue Pagination
A Vue.js pagination component for Laravel paginators that works with Bootstrap
Stars: ✭ 541 (-1.99%)
Mutual labels:  laravel
Snooze
A package to simplify automating future notifications and reminders in Laravel
Stars: ✭ 515 (-6.7%)
Mutual labels:  laravel
Blade
🔪 A standalone version of Laravel's Blade templating engine for use outside of Laravel.
Stars: ✭ 542 (-1.81%)
Mutual labels:  laravel
Laravel Model Status
Easily add statuses to your models
Stars: ✭ 510 (-7.61%)
Mutual labels:  laravel
Laravel Firewall
Web Application Firewall (WAF) package for Laravel
Stars: ✭ 544 (-1.45%)
Mutual labels:  laravel
Laravel Eloquent Query Cache
Adding cache on your Laravel Eloquent queries' results is now a breeze.
Stars: ✭ 529 (-4.17%)
Mutual labels:  laravel
Init.engineer
這是一份純靠北工程師的專案,請好好愛護它,謝謝。
Stars: ✭ 528 (-4.35%)
Mutual labels:  laravel
Laravel Blade X
Use custom HTML components in your Blade views
Stars: ✭ 538 (-2.54%)
Mutual labels:  laravel

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 composer.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 manually add the service provider and alias if working on Laravel version lower then 5.5

To start using Laravel, add the Service Provider and the Facade to your config/app.php:

'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:

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() {
	$data = [
		'foo' => 'bar'
	];
	$pdf = PDF::loadView('pdf.document', $data);
	return $pdf->stream('document.pdf');
}

Other methods

It is also possible to use the following methods on the pdf object:

output(): Outputs the PDF as a string.
save($filename): Save the PDF to a file
download($filename): Make the PDF downloadable by the user.
stream($filename): Return a response with the PDF to show in the browser.

Config

If you have published config file, you can change the default settings in config/pdf.php file:

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 Footers

If you want to have headers and footers that appear on every page, add them to your <body> tag like this:

<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 {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 [
	// ...
	'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 laravel-pdf 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 CSS:

body {
	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-forms', 'fill-forms', 'extract', 'assemble', 'print-highres'.

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 SetProtection() here: https://mpdf.github.io/reference/mpdf-functions/setprotection.html

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 license

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].