2017 © Pedro Peláez
 

library laravel-pdf

Laravel PDF - for generating pdf invice or documents.

image

zanysoft/laravel-pdf

Laravel PDF - for generating pdf invice or documents.

  • Wednesday, July 18, 2018
  • by mubasharahmad
  • Repository
  • 1 Watchers
  • 1 Stars
  • 6,505 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 5 Versions
  • 18 % Grown

The README.md

Laravel PDF: PDF generator for Laravel

Easily generate PDF documents from HTML right inside of Laravel using this PDF wrapper., (*1)

Contents

Installation Guide

Require this package in your composer.json or install it by running:, (*2)

composer require zanysoft/laravel-pdf

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

'providers' => [
    // ...
    ZanySoft\LaravelPDF\PdfServiceProvider::class
]
'aliases' => [
    // ...
    'PDF' => ZanySoft\LaravelPDF\Facades\PDF::class
]

Configuration

The defaults configuration settings are set in config/pdf.php. Copy this file to your own config directory to modify the values. You can publish the config using this command:, (*4)

php artisan vendor:publish --provider="ZanySoft\LaravelPDF\PdfServiceProvider"

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., (*5)

    use ZanySoft\LaravelPDF\Facades\PDF;

    $data = ['foo' => 'bar'];
    $pdf = PDF::make('document.pdf');
    $pdf->loadView('pdf.document', $data);

    return $pdf->stream();

or, (*6)

    use ZanySoft\LaravelPDF\PDF;

    $pdf = new PDF();
    $pdf->loadView('pdf.document', $data);

    return $pdf->stream('document.pdf');

If you want to generate from html content:, (*7)

    $content = "Hello this is first pdf file."
    $pdf->loadHTML($content);

    return $pdf->stream('document.pdf');

If you want to generate from files:, (*8)

    $file = "file.txt"
    $pdf->loadFile($file);

    return $pdf->stream('document.pdf');

If you want download pdf file:, (*9)

    return $pdf->embed('document.pdf');

If you want to save pdf to server:, (*10)

    return $pdf->save('with-complete-path/document.pdf');

If you want add pdf file as attachment to email:, (*11)

    return $pdf->embed('document.pdf');

Headers and Footers

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

<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:, (*13)

@page {
    header: page-header;
    footer: page-footer;
}

Inside of headers and footers {PAGENO} can be used to display the page number., (*14)

Included Fonts

By default you can use all the fonts shipped with mPDF., (*15)

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):, (*16)

    return [
        'custom_font_path' => base_path('/resources/fonts/'), // don't forget the trailing slash!
    ];

And then:, (*17)

    $fontdata = array(
        '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
        ]
        // ...add as many as you want.
    );

    $pdf->addCustomFont($fontdata, true);
    // If your font file is unicode and "OpenType Layout" then set true. Default value is false.

Now you can use the font in CSS:, (*18)

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., (*19)

The passwords are optional., (*20)

There are a few permissions: 'copy', 'print', 'modify', 'annot-forms', 'fill-forms', 'extract', 'assemble', 'print-highres'., (*21)

use PDF;

function generate_pdf() {
    $data = [
        'foo' => 'bar'
    ];
    $pdf = PDF::make();
    $pdf->SetProtection(['copy', 'print'], 'user_pass', 'owner_pass')
    $pdf->loadView('pdf.document', $data);

    return $pdf->stream('document.pdf');
}

Find more information to SetProtection() here: https://mpdf.github.io/reference/mpdf-functions/setprotection.html, (*22)

Documentation

Visit this link for more options and settings: https://mpdf.github.io/, (*23)

The Versions

18/07 2018

dev-master

9999999-dev http://www.zanysoft.co

Laravel PDF - for generating pdf invice or documents.

  Sources   Download

MIT

The Requires

 

laravel pdf adobe laravel-pdf pdf-invoice pdf-documents

18/07 2018

v1.0.3

1.0.3.0 http://www.zanysoft.co

Laravel PDF - for generating pdf invice or documents.

  Sources   Download

MIT

The Requires

 

laravel pdf adobe laravel-pdf pdf-invoice pdf-documents

29/05 2017

v1.0.2

1.0.2.0

Laravel PDF

  Sources   Download

MIT

The Requires

 

20/02 2017

v1.0.1

1.0.1.0

Laravel PDF

  Sources   Download

MIT

The Requires

 

by Mubashar Ahmad Nasir

20/02 2017

1.0.1.x-dev

1.0.1.9999999-dev

Laravel PDF

  Sources   Download

MIT

The Requires

 

by Mubashar Ahmad Nasir