All Projects → nahidulhasan → Laravel Pdf

nahidulhasan / 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.

Projects that are alternatives of or similar to Laravel Pdf

Laravel Short Url
A Laravel package to shorten urls
Stars: ✭ 127 (+60.76%)
Mutual labels:  laravel, laravel-package, laravel5, package
Laravel Settings
Simple Settings package for a laravel application
Stars: ✭ 45 (-43.04%)
Mutual labels:  laravel, laravel-package, laravel-5-package, laravel5
Blogetc
Easily add a full Laravel blog (with built in admin panel and public views) to your laravel project with this simple package.
Stars: ✭ 198 (+150.63%)
Mutual labels:  laravel, laravel-package, laravel-5-package, package
Eye
Eyewitness.io package for Laravel 5 applications
Stars: ✭ 114 (+44.3%)
Mutual labels:  laravel, laravel-package, laravel-5-package, laravel5
Laravel Email Verification
Laravel package to handle user verification using an activation mail
Stars: ✭ 63 (-20.25%)
Mutual labels:  laravel, laravel-package, laravel-5-package, laravel5
Auth Tests
Always-current tests for Laravel's authentication system. Curated by the community.
Stars: ✭ 230 (+191.14%)
Mutual labels:  laravel, laravel-package, laravel-5-package, laravel5
Laravel Gitscrum
GitScrum is a Project Management Tool, developed to help entrepreneurs, freelancers, managers, and teams Skyrocket their Productivity with the Agile methodology and Gamification.
Stars: ✭ 2,686 (+3300%)
Mutual labels:  laravel, laravel-package, laravel-5-package, package
Laravel Remember Uploads
Laravel Middleware and helper for remembering file uploads during validation redirects
Stars: ✭ 67 (-15.19%)
Mutual labels:  laravel, laravel-package, laravel-5-package
Twitter
Twitter API for Laravel 5.5+, 6.x, 7.x & 8.x
Stars: ✭ 755 (+855.7%)
Mutual labels:  laravel, laravel-package, laravel5
Package Skeleton
📦 My base for PHP packages.
Stars: ✭ 6 (-92.41%)
Mutual labels:  laravel, laravel-package, package
Angular5.2 Laravel5.6
Angular 5.2 and Laravel 5.6 Authentication and CRUD
Stars: ✭ 17 (-78.48%)
Mutual labels:  laravel, laravel-5-package, laravel5
Laravel Aws Sns
Laravel package for the AWS SNS Events
Stars: ✭ 24 (-69.62%)
Mutual labels:  laravel, laravel-package, package
Blade Migrations Laravel
An intelligent alternative version of Laravel 5/6 Database Migrations - uses raw-sql syntax, transactions, auto-rollback, UP-DOWN-UP testing
Stars: ✭ 25 (-68.35%)
Mutual labels:  laravel, laravel-package, laravel5
Laravel User Verification
PHP package built for Laravel 5.* to easily handle a user email verification and validate the email
Stars: ✭ 755 (+855.7%)
Mutual labels:  laravel, laravel-package, laravel5
Orm
A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen
Stars: ✭ 712 (+801.27%)
Mutual labels:  laravel, laravel-package, laravel-5-package
Laravel Widgetize
A minimal package to help you make your laravel application cleaner and faster.
Stars: ✭ 791 (+901.27%)
Mutual labels:  laravel, laravel-5-package, laravel5
Framework
The truly Laravel E-commerce Framework
Stars: ✭ 456 (+477.22%)
Mutual labels:  laravel, laravel-package, laravel5
Laravel Js Localization
🌐 Convert your Laravel messages and consume them in the front-end!
Stars: ✭ 451 (+470.89%)
Mutual labels:  laravel, laravel-package, laravel-5-package
Larrock Core
Core components for LarrockCMS
Stars: ✭ 46 (-41.77%)
Mutual labels:  laravel, laravel-5-package, laravel5
Notifier
NO LIBRARIES socket per page bridge for your Laravel application. (CLIENT PART INCLUDED)
Stars: ✭ 57 (-27.85%)
Mutual labels:  laravel, laravel-5-package, laravel5

Laravel-Html2Pdf

Latest Stable Version Total Downloads Latest Unstable Version License

A Simple package for easily generating PDF documents from HTML.This package is specially for laravel but you can use this without laravel.

Installation

Install wkhtmltopdf

This was tested on:

  • Ubuntu 14.04 x64
  • Ubuntu 16.04 x64
sudo apt-get update
sudo apt-get install xvfb libfontconfig wkhtmltopdf

For docker

RUN apt-get update && apt-get install xvfb libfontconfig wkhtmltopdf

Upddate Composer

composer require nahidulhasan/html2pdf

If laravel version < 5.5, add the ServiceProvider to the providers array in config/app.php

NahidulHasan\Html2pdf\Html2pdfServiceProvider::class,

You can optionally use the facade for shorter code. Add this to your facades:

'Pdf'  => NahidulHasan\Html2pdf\Facades\Pdf::class,

Basic Usage

To create PDF add something like this to one of your controllers.

use NahidulHasan\Html2pdf\Facades\Pdf;

$document = Pdf::generatePdf('<h1>Test</h1>');

You can also create PDF from directly calling laravel blade file. Suppose you have a mail template named greeting in view/mails folder and want to send parameter then you have to call generatePdf method as described in below

<!-- mail template stored in resources/views/mails/greeting.blade.php -->

$document =  Pdf::generatePdf(view('mails.greeting', ['name' => 'James', 'testVar' => 'demo']));


Now If you want to send mail to your client attaching pdf then you can follow this code

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->from('[email protected]')
                ->view('mails.demo')
                ->attachData($document, 'Invoice.pdf');
}
  

Download pdf

Save the PDF to a file in a specific folder, and then download it

use NahidulHasan\Html2pdf\Pdf;

$obj = new Pdf();

$html = '<html><body>'
    . '<p>Put your html here, or generate it with your favourite '
    . 'templating system.</p>'
    . '</body></html>';

$invoice = $obj->generatePdf($html);

define('INVOICE_DIR', public_path('uploads/invoices'));

if (!is_dir(INVOICE_DIR)) {
    mkdir(INVOICE_DIR, 0755, true);
}

$outputName = str_random(10);
$pdfPath = INVOICE_DIR.'/'.$outputName.'.pdf';


File::put($pdfPath, $invoice);

$headers = [
    'Content-Type' => 'application/pdf',
    'Content-Disposition' =>  'attachment; filename="'.'filename.pdf'.'"',
];

return response()->download($pdfPath, 'filename.pdf', $headers);

Other Usage

It is also possible to use the following methods :

pdf::stream('<h1>Test</h1>') Open the PDF file in browser

Running without Laravel

You can use this library without using Laravel.

Example:

use NahidulHasan\Html2pdf\Pdf;

$obj = new Pdf();
$document = $obj->generatePdf('<h1>Test</h1>');

License

Html2PDF for Laravel 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].