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

TuffRivers's avatar

Chrome-PHP Pdf

I feel like im going insane, I have imported chrome-php into my laravel application. I want to

  1. Create a page object
  2. Inject my HTML
  3. Generate a PDF

But i cant seem to get any of my CSS styles to render even if they are inline (ie not using blade partials).

This is my code, am i doing something wrong? I can get images to render fine, just not CSS is applied excelt like font-weight bold, its very, very odd. I have logged my $html and i see valid HTML with all my blade components and all my css is directly accessible

eg

<link rel="stylesheet" href="https://app.mydomain.com/assets/css/form.css">
        $html = view('forms.pdf', ['data' => $data])->render();

        try {
            $page = $browser->createPage();
            $page->setHtml($html);
            $pdf = $page->pdf(['printBackground' => true]);
            $pdf->saveToFile($pdfFullPath);
        } finally {
            // Always ensure that the browser is closed
            $browser->close();
        }

Any ideas?

0 likes
3 replies
TuffRivers's avatar

@Lirux trying to use this as well, nothing seems to work..

        Browsershot::url('https://google.com')
        ->format('Letter')
        ->setNodeBinary('/usr/bin/node') // Adjust if your node binary is located elsewhere
        ->setNpmBinary('/usr/bin/npm') // Adjust if your npm binary is located elsewhere
        ->setChromePath('/usr/bin/google-chrome') // Set the correct path to the Chrome binary
       // ->noSandbox()
        ->save($pdfFullPath);

Output:

Error Output:

ReferenceError: ReadableStream is not defined

amcardwell's avatar

I'm having this issue as well. "ReadableStream is not defined"

Please or to participate in this conversation.