Skip to content

Commit

Permalink
Save on disk using Browsershot save() directly
Browse files Browse the repository at this point in the history
  • Loading branch information
aalyusuf committed Nov 17, 2024
1 parent 32c5ab1 commit fa0f639
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/PdfBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit fa0f639

Please sign in to comment.