Download the PHP package gocanto/laravel-simple-pdf without Composer
On this page you can find all versions of the php package gocanto/laravel-simple-pdf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-simple-pdf
About it
This library is a minimalist on demand and immutable PDF generator
for Laravel. It aims to keep a small friction once you need to generate a printable file using a intuitive public API.
Simple PDF is shipped with a default template that you will be able to use to frame your next PDF files. You can see its layout here
Installation
This library uses Composer to manage its dependencies. So, before using it, make sure you have it installed in your machine. Once you have done this, you will be able to pull this library in by typing the following command in your terminal.
Default template implementation
Using the default template is the easiest way to get started. Like so:
What's going on here ?
-
First of all, we imported the
Builder
and theTemplate Context
objects; you can think about them as the manager to generate your PDF files. For instance, theBuilder
is the one on charge of creating theStream File
we will be rendering on demand while the another one holds the data to be display within the default template. -
Second of all, we created the
TemplateContext
object with the desired data to be shown in our PDF file. The context object is a simple value object that holds some handy methods to manipulate the given array within our blade files. See more - Lastly, we invoke the
make
method passing in our context object and finish by returning with therender
functionality.
Custom template implementation
This implementation is done out of the same API, but it has a bit of configuration on the top. Like so:
As you can see, the first three steps
are the same as the default implementation, so there is no need to explain further on this regard. Now, we need to clarify the differences on its
setup.
-
First of all, we tell the builder about our templates root folder by invoking the
addLocation
method. This way, we will be able to have a views root folder to keep our different templates. -
Second of all, we will register the custom templates by calling the
withTemplate
method. Please, do bear in account this is an immutable method, therefore, we will have a newBuilder
instance as result. - Lastly, we will call the
make
andrender
method in the same way we did with the default template above.
Features
- Multi templates ability.
- The state is immutable, meaning all the withers as
withStream
,withTemplate
andwithHeaders
methods will return a new instance of theBuilder
. - The exported stream is expose for custom manipulations, meaning you can pass a call back to the render method to manipulate the given stream before rendering time. Like so:
TO DO
- [ ] (Gus) Allow rendered HTML or Blades files template as part of the
TemplateContext
content field. - [ ] (interested?) Allow more engines like twig.
- [ ] (interested?) Make it framework agnostic.
Contributing
Please feel free to fork this package and contribute by submitting a pull request to enhance its functionality.
License
The MIT License (MIT). Please see License File for more information.
How can I thank you?
Why not star the github repo and share the link for this repository on Twitter?
Don't forget to follow me on twitter!
Thanks!
Gustavo Ocanto.
All versions of laravel-simple-pdf with dependencies
dompdf/dompdf Version ^0.8.3
guzzlehttp/guzzle Version ^6.3
illuminate/contracts Version ^5.8
illuminate/support Version ^5.8
illuminate/view Version ^5.8
psr/http-message Version ^1.0
symfony/http-foundation Version ^4.3