https://github.com/refaltor77/easypdf
A very easy-to-use library that allows you to generate PDFs from Blade views with minimal effort.
https://github.com/refaltor77/easypdf
blade-template composer-package easy-pdf laravel laravel-package library mpdf open-source pdf pdf-document pdf-generation pdf-viewer php php-library template-engin
Last synced: about 2 months ago
JSON representation
A very easy-to-use library that allows you to generate PDFs from Blade views with minimal effort.
- Host: GitHub
- URL: https://github.com/refaltor77/easypdf
- Owner: Refaltor77
- License: mit
- Created: 2024-12-28T15:34:48.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-28T15:37:55.000Z (over 1 year ago)
- Last Synced: 2025-01-09T03:47:25.216Z (over 1 year ago)
- Topics: blade-template, composer-package, easy-pdf, laravel, laravel-package, library, mpdf, open-source, pdf, pdf-document, pdf-generation, pdf-viewer, php, php-library, template-engin
- Language: PHP
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# EasyPdf
`EasyPdf` is a library that enables the creation of PDFs using Blade templates and the Mpdf library. It provides an easy-to-use interface for generating PDFs from Blade views, with options for saving or streaming the generated PDF.
## Features
- **Blade Template Integration**: Use Blade templates to generate HTML content for PDFs.
- **Mpdf Integration**: Leverage Mpdf for high-performance PDF generation.
- **Save or Stream PDFs**: Save PDFs to a file or stream them directly to the browser.
## Installation
You can install the package via Composer:
```bash
composer require elysio/easy-pdf
```
## Usage
### Initialize the EasyPdf instance
To initialize the `EasyPdf` class, you can either use the constructor directly or the static `init` method.
```php
use elysio\easypdf\EasyPdf;
$pdfGenerator = EasyPdf::init('path/to/views', 'path/to/cache');
```
### Generate a PDF
You can generate a PDF from a Blade view by calling the `makePdf` method. The method takes the name of the Blade view and an optional array of data to be passed to the view.
```php
$pdf = $pdfGenerator->makePdf('viewName', ['key' => 'value']);
```
This will return an `Mpdf` instance, which you can use for further operations (e.g., saving or streaming the PDF).
### Save the PDF
To save the generated PDF to a file, use the `savePdf` method:
```php
$success = $pdfGenerator->savePdf($pdf, 'path/to/save/document.pdf');
```
### Stream the PDF
To stream the generated PDF directly to the browser, use the `streamPdf` method:
```php
$pdfGenerator->streamPdf($pdf, 'document.pdf');
```
## Configuration
The `EasyPdf` class allows you to specify custom paths for the Blade views and cache directories when initializing the instance.
```php
$pdfGenerator = EasyPdf::init('custom/views', 'custom/cache');
```
## Dependencies
- **mpdf/mpdf**: Required for PDF generation.
- **eftec/bladeone**: Required for Blade templating.
## Development
To run tests during development, use the following command:
```bash
composer test
```
This will execute the tests using Pest.
## License
MIT License. See the [LICENSE](LICENSE) file for more information.
## Author
**Elysio Martins | Refaltor**
Email: [elysiomartinspro@gmail.com](mailto:elysiomartinspro@gmail.com)