From fa0f63933f59042b9297a62449b8ac246de2cf21 Mon Sep 17 00:00:00 2001 From: "A. Alyusuf" Date: Sun, 17 Nov 2024 13:40:21 +0000 Subject: [PATCH] Save on disk using Browsershot save() directly --- src/PdfBuilder.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/PdfBuilder.php b/src/PdfBuilder.php index 0bcfd45..7be775a 100755 --- a/src/PdfBuilder.php +++ b/src/PdfBuilder.php @@ -10,6 +10,7 @@ use Spatie\LaravelPdf\Enums\Format; use Spatie\LaravelPdf\Enums\Orientation; use Spatie\LaravelPdf\Enums\Unit; +use Spatie\TemporaryDirectory\TemporaryDirectory; use Wnx\SidecarBrowsershot\BrowsershotLambda; class PdfBuilder implements Responsable @@ -257,10 +258,19 @@ public function disk(string $diskName, string $visibility = 'private'): self protected function saveOnDisk(string $diskName, string $path): self { - $pdfContent = $this->getBrowsershot()->pdf(); - $visibility = $this->visibility; + $fileName = pathinfo($path, PATHINFO_BASENAME); - Storage::disk($diskName)->put($path, $pdfContent, $visibility); + $temporaryDirectory = (new TemporaryDirectory)->create(); + + $this->getBrowsershot()->save($temporaryDirectory->path($fileName)); + + $content = file_get_contents($temporaryDirectory->path($fileName)); + + $temporaryDirectory->delete(); + + $visibility = $this->visibility; + + Storage::disk($diskName)->put($path, $content, $visibility); return $this; }