Skip to content

Commit

Permalink
feat: add dompdf driver
Browse files Browse the repository at this point in the history
  • Loading branch information
muhajirrr committed May 25, 2024
1 parent 5baf08a commit 58651bc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"require": {
"php": "^8.1",
"barryvdh/laravel-dompdf": "^2.2",
"barryvdh/laravel-snappy": "^1.0",
"illuminate/contracts": "^10.0",
"spatie/browsershot": "^3.58",
Expand Down
4 changes: 2 additions & 2 deletions config/documents.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
/*
* Specifies the default driver used for document pdf generation.
*
* Supported: "snappy", "browsershot"
* Supported: "dompdf", "snappy", "browsershot"
*/

'default_driver' => env('DOCUMENT_DRIVER', 'snappy'),
'default_driver' => env('DOCUMENT_DRIVER', 'dompdf'),
];
6 changes: 6 additions & 0 deletions src/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use AsevenTeam\Documents\Contract\Driver;
use AsevenTeam\Documents\Drivers\BrowsershotDriver;
use AsevenTeam\Documents\Drivers\DompdfDriver;
use AsevenTeam\Documents\Drivers\DriverDecorator;
use AsevenTeam\Documents\Drivers\SnappyDriver;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -49,6 +50,11 @@ protected function createSnappyDriver(): Driver
return new SnappyDriver();
}

protected function createDompdfDriver(): Driver
{
return new DompdfDriver();
}

protected function getDefaultDriver(): string
{
return config('documents.default_driver');
Expand Down
16 changes: 16 additions & 0 deletions src/Drivers/DompdfDriver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace AsevenTeam\Documents\Drivers;

use AsevenTeam\Documents\Contract\Driver;
use Barryvdh\DomPDF\Facade\Pdf;

class DompdfDriver implements Driver
{
public function render(string $html, array $options = []): string
{
return Pdf::loadHTML($html)
->setPaper($options['page-size'] ?? 'a4', $options['orientation'] ?? 'portrait')
->output();
}
}
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use AsevenTeam\Documents\DocumentServiceProvider;
use Barryvdh\Snappy\ServiceProvider as SnappyServiceProvider;
use Barryvdh\DomPDF\ServiceProvider as DompdfServiceProvider;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Expand All @@ -25,6 +26,7 @@ protected function getPackageProviders($app)
return [
DocumentServiceProvider::class,
SnappyServiceProvider::class,
DompdfServiceProvider::class,
];
}

Expand Down

0 comments on commit 58651bc

Please sign in to comment.