Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Dec 29, 2023
1 parent e03e60b commit 2933233
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
23 changes: 22 additions & 1 deletion docs/advanced-usage/generating-pdfs-on-aws-lambda.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,25 @@ title: Generating PDFs on AWS Lambda
weight: 3
---

Coming soon...
Generating PDFs locally can be resource intensive. If you're having to generate a lot of PDFs, or having troubles to install the necessary dependencies on your server, you may want to consider using AWS Lambda to generate your PDFs.

In order to generate PDFs on AWS Lambda, you must install these two packages in your app.

- [hammerstone/sidecar](https://hammerstone.dev/sidecar/docs/main/overview): this allows you to execute AWS Lambda functions from your Laravel applicatio
- [wnx/sidecar-browsershot](https://github.com/wnx/sidecar-browsershot): this package contains a version of Browsershot that can run on AWS Lambda via Sidecar.

With these two packages installed, you can generate PDFs on AWS Lambda like this:

```php
Pdf::view('pdf.invoice', $data)
->generateOnLambda()
->save('invoice.pdf');
```

If you want to create all PDFs in your app on Lambda, you can [set it as a default](https://spatie.be/docs/laravel-pdf/v1/basic-usage/setting-defaults) like this:

```php
// typically, in a service provider

Pdf::default()->generateOnLambda();
```
8 changes: 4 additions & 4 deletions src/PdfBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class PdfBuilder implements Responsable
'Content-Type' => 'application/pdf',
];

protected bool $useLambda = false;
protected bool $generateOnLambda = false;

public function view(string $view, array $data = []): self
{
Expand Down Expand Up @@ -207,9 +207,9 @@ public function withBrowsershot(callable $callback): self
return $this;
}

public function useLambda(): self
public function generateOnLambda(): self
{
$this->useLambda = true;
$this->generateOnLambda = true;

return $this;
}
Expand Down Expand Up @@ -264,7 +264,7 @@ protected function getFooterHtml(): ?string

protected function getBrowsershot(): Browsershot
{
$browsershotClass = $this->useLambda
$browsershotClass = $this->generateOnLambda
? BrowsershotLambda::class
: Browsershot::class;

Expand Down

0 comments on commit 2933233

Please sign in to comment.