mccarlosen / laravel-mpdf

Generate PDFs in Laravel with Mpdf.
402 stars 107 forks source link

[Feature request] Please make MPdf Macroable #87

Closed realtebo closed 2 years ago

realtebo commented 2 years ago

Hi !

As title, we ask you kindly to implement Macroable in this project so we can add macro instead of creating custom helpers as shortcut.

newtonjob commented 2 years ago

@mccarlosen thanks a bunch for this wrapper.

Could you help us pop the Macroable trait in the LaravelMpdfWrapper?

mccarlosen commented 2 years ago

Hi guys!

Could you give me an example? How would you use it?

newtonjob commented 2 years ago

@mccarlosen

By adding the Macroable trait to the LaravelMpdf, we could extend the class with custom methods for our own use case.

For example, I may want to add a method that returns a base64 representation of the Pdf string.

LaravelMpdf::macro('base64', function () {
    return base64_encode($this->output());
});

Then it could be used like so;

$base64_string = PDF::loadView('pdf.document', $data)->base64();

Thanks

realtebo commented 2 years ago

Also, we can create a ::init to return a new instance with some defaults about security, etc

mccarlosen commented 2 years ago

Hello guys!

The package has been updated to version 2.1.9.

Please, You may update your composer file and start using this new feature.