PDF

Codacy Badge StyleCI License Total Downloads Latest Stable Version

PDF utility package for Laravel Enso

This package can work independently of the Enso ecosystem.

For live examples and demos, you may visit laravel-enso.com

Watch the demo

click on the photo to view a a larger screenshot

Installation

install using composer: composer require laravel-enso/pdf

Features

  • is a small wrapper that uses laravel-snappy under the hood using the pdftk package for this purpose
  • utilizes a series of common defaults for the page, with the option of overriding them
    • setting the page orientation to landscape (by default is portrait)
    • setting options for the snappy pdf object, such as margins, footer, etc. (for more options, look here)
  • can provide the generated pdf document inline (for downloads) or save the file to disk

Usage

In order to generate a PDF using the default options, you need to provide a view together with the set of variables for that view, and then call the inline method:

$pdf = new Pdf();
$pdf->loadView(
  'pdf.myBlade', 
  [
      'data' => $myData
  ]
)
->inline();

If you want to customize the defaults, before calling the inline method, you may chain any modifier methods:

 $pdf = new Pdf();
 $pdf->loadView(
   'pdf.myBlade', 
   [
       'data' => $myData
   ]
 )
 ->landscape()
 ->inline();

Available methods

The following methods are required:

  • loadView(string $view, array $attributes), loads/sets the view that is to be used for the generation of the pdf, together with the attributes used in that view
  • inline(), generates the pdf and returns it as a stream, for download OR
  • save($filePath), generates the pdf and saves it on the given path

The following modifier methods are available:

  • landscape(), set the page orientation as landscape (default is portrait)
  • setOption(string $option, $value), set the value for the given option. For a list of options, look here

External dependencies

Contributions

are welcome. Pull requests are great, but issues are good too.

License

This package is released under the MIT license.