Skip to content

Commit

Permalink
Fixes of installations for Laravel less than 8, fixes of tests and do…
Browse files Browse the repository at this point in the history
…cumentation improvements
  • Loading branch information
misterspelik committed Nov 13, 2023
1 parent ea9af48 commit 261468f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To start using Laravel, add the Service Provider and the Facade to your `config/
```php
'providers' => [
// ...
misterspelik\LaravelPdf\PdfServiceProvider::class
misterspelik\LaravelPdf\Providers\PdfServiceProvider::class
]
```

Expand Down Expand Up @@ -74,7 +74,7 @@ return [
'subject' => 'This Document will explain the whole universe.',
'keywords' => 'PDF, Laravel, Package, Peace', // Separate values with comma
'creator' => 'Laravel Pdf',
'display_mode' => 'fullpage'
'display_mode' => 'fullpage',
];
```

Expand Down Expand Up @@ -163,9 +163,8 @@ You can use your own styles in the generated PDFs. The css file have to be locat

```php
return [
...
'defaultCssFile' => base_path('public/css/pdf.css'),
...
//...
'defaultCssFile' => base_path('public/css/pdf.css'),
];
```

Expand All @@ -180,18 +179,36 @@ There are a fews permissions: `'copy'`, `'print'`, `'modify'`, `'annot-forms'`,
```php
use PDF;

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

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

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

## PDF Wrapper extension

This package has own wrapper for the Mpdf\Mpdf class. But it can be also overrided or extended on the project level.

There is a setting in the config file to use a custom PdfWrapper.

```php
return [
// ...
'pdfWrapper' => 'misterspelik\LaravelPdf\Wrapper\PdfWrapper',
];
```

The only requirement that the wrapper must implement the interface
`misterspelik\LaravelPdf\PdfInterface\PdfWrapperInterface`

## Testing

To use the testing suite, you need some extensions and binaries for your local PHP. On macOS, you can install them like this:
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"ext-gd": "*",
"ext-imagick": "*",
"ext-mbstring": "*",
"misterspelik/mpdf": "^8.1.6"
"misterspelik/mpdf": "^8.1.6",
"psr/http-message": "^1.1 || ^2.0",
"psr/log": "^1.1.0 || ^2.0.0 || ^3.0.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6.0",
Expand All @@ -33,7 +35,7 @@
"extra": {
"laravel": {
"providers": [
"misterspelik\\LaravelPdf\\PdfServiceProvider"
"misterspelik\\LaravelPdf\\Providers\\PdfServiceProvider"
],
"aliases": {
"PDF": "misterspelik\\LaravelPdf\\Facades\\Pdf"
Expand Down
14 changes: 11 additions & 3 deletions src/LaravelPdf/Providers/PdfServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Support\ServiceProvider;
use misterspelik\LaravelPdf\LaravelPdfFactory;
use misterspelik\LaravelPdf\Wrapper\PdfWrapper;
use misterspelik\LaravelPdf\Wrapper\PdfWrapperInterface;

class PdfServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -56,8 +56,8 @@ public function register()
__DIR__ . '/../../config/pdf.php', 'pdf'
);

$this->app->bind('mpdf.wrapper', function($app) {
return $this->factory->createPdfWrapper();
$this->app->bind('mpdf.wrapper', function ($app) {
return $this->getPdfWrapper();
});
}

Expand All @@ -72,4 +72,12 @@ public function provides()
'mpdf.pdf'
];
}

/**
* @return \misterspelik\LaravelPdf\Wrapper\PdfWrapperInterface
*/
protected function getPdfWrapper(): PdfWrapperInterface
{
return $this->factory->createPdfWrapper();
}
}
1 change: 0 additions & 1 deletion tests/PdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ protected function compareToSnapshot(string $snapshotId, $data): void
// create snapshot if it doesn't exist
if (!file_exists($snapshotFile)) {
file_put_contents($snapshotFile, $data);
return;
}

$snapshot = file_get_contents($snapshotFile);
Expand Down
Binary file modified tests/snapshots/exposify.pdf
Binary file not shown.

0 comments on commit 261468f

Please sign in to comment.