Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ecmrnn's avatar
Level 3

Need help implementing spatie/laravel-pdf on production using Laravel Forge

Generating PDFs locally works perfectly fine, here's my PDF generating job class:

 public function handle()
     {
         return Pdf::view('pdf.reservations.reservation_pdf', [
             'reservation' => $this->reservation
         ])
         ->withBrowsershot(function (Browsershot $browsershot) {
             $browsershot->noSandbox();
         })
         ->format('letter')
         ->margins(
             $this->margin['top'],
             $this->margin['right'],
             $this->margin['bottom'],
             $this->margin['left'],
             Unit::Pixel
         )
         ->save(storage_path($this->path));
    }

Here's the output of my logs in laravel forge when trying to generate a PDF:

Error Output:
================
Error: ENOENT: no such file or directory, open '/home/forge/mydomain/storage/app/public/pdf/reservation/R250410002 - MARANAN_EC.pdf'
    at async Object.open (node:internal/fs/promises:638:25)
    at async getReadableAsTypedArray (/home/forge/mydomain/node_modules/puppeteer-core/lib/cjs/puppeteer/common/util.js:169:28)
    at async CdpPage.pdf (/home/forge/mydomain/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Page.js:827:28)
    at async getOutput (/home/forge/mydomain/vendor/spatie/browsershot/bin/browser.cjs:49:28)
    at async callChrome (/home/forge/mydomain/vendor/spatie/browsershot/bin/browser.cjs:402:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/home/forge/mydomain/storage/app/public/pdf/reservation/R250410002 - MARANAN_EC.pdf'
}
 {"exception":"[object] (Symfony\\Component\\Process\\Exception\\ProcessFailedException(code: 0):

Using DigitalOcean and OS is Ubuntu 24.04.

I also have followed the instruction and installed the necessary requirements given by spatie. I also have confirmed that npm, node, chrome, and puppeteer as well as the dependencies are installed in the server.

0 likes
1 reply
ecmrnn's avatar
ecmrnn
OP
Best Answer
Level 3

Solved

For those encountering this error, what I did is manually creating the directories that is needed to store the generated PDF.

  1. ssh [email protected]
  2. cd /home/forge/mydomain/storage/app/public/
  3. mkdir path

Please or to participate in this conversation.