October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

Convert HTML to PDF in Laravel with Browsershot

Use Spatie Browsershot to save trusted HTML as a PDF in Laravel, or render a Blade view with Laravel PDF. Learn the runtime requirements, driver differences, and common fixes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To turn an HTML string into a PDF with Spatie Browsershot, pass it to Browsershot::html() and call savePdf(). Browsershot v4 requires Node.js 22.0 or higher and Puppeteer 23.0 or higher, plus an available Chrome browser. Validate HTML and URLs before rendering: a browser process should not receive arbitrary user input.

This guide covers direct Browsershot use and, separately, the Laravel PDF package’s Blade-view workflow. Their package generations and driver requirements differ.

As an Amazon Associate I earn from qualifying purchases.

Render an HTML string directly with Browsershot

Install and configure Spatie Browsershot v4 and its browser runtime first. Then render trusted HTML and save the PDF to an application-managed path:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<?php

use SpatieBrowsershotBrowsershot;

$html = '<!doctype html><html><body><h1>Invoice</h1><p>Paid</p></body></html>';

Browsershot::html($html)
    ->format('A4')
    ->savePdf(storage_path('app/example.pdf'));

The direct HTML-to-PDF call is documented by Spatie Browsershot v4. The example uses an A4 page; change the format and destination to suit your document and storage policy.

Render a URL instead

Browsershot can also visit a URL and save the page as a PDF:

Browsershot::url($url)
    ->savePdf(storage_path('app/page.pdf'));

Only render URLs your application is allowed to access. Validate and constrain them before passing them to the browser.

Adjust the PDF output

Browsershot supports options including paper format or size, margins, headers and footers, and page selection. Use the documented options for the exact output you need rather than assuming browser print defaults will match your intended layout; see the PDF creation documentation.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set up the Browsershot runtime

Browsershot v4 documents Node.js 22.0 or later and Puppeteer 23.0 or later as requirements. It also needs a Chrome browser. Follow the v4 setup instructions to install the dependencies and, when automatic discovery fails, configure the executable paths.

  • Check the Node.js and Puppeteer versions against the v4 requirements.
  • Confirm Chrome or Chromium is installed and accessible to the PHP process in the environment that generates PDFs.
  • If a binary is installed outside the expected location, configure its path using Browsershot’s documented settings.
  • Check process permissions and deployment or container configuration; local development success does not establish compatibility in another environment.

Generate a PDF from a Blade view

If you want Laravel-facing view rendering rather than calling Browsershot directly, Spatie Laravel PDF v2 documents rendering a Blade view with its facade:

<?php

use SpatieLaravelPdfFacadesPdf;

Pdf::view('pdf.invoice', ['invoice' => $invoice])
    ->save(storage_path('app/invoice.pdf'));

Laravel PDF v2 also supports an HTML string. Its PDF creation guide shows the view and HTML workflows. Confirm which driver is configured before relying on JavaScript execution or assuming a particular runtime.

Choose a driver for your layout and deployment

Laravel PDF v2 offers multiple drivers; they are not interchangeable in runtime requirements or rendering behavior. Its driver overview describes Browsershot, Gotenberg, Cloudflare, and Chrome as supporting modern CSS features; WeasyPrint as strong for CSS Paged Media; and DOMPDF for simpler layouts.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Choice What the documentation establishes Consider it when
Browsershot The Laravel PDF Browsershot driver depends on the Browsershot package and its runtime requirements. You need browser rendering and can provide the required local runtime.
Cloudflare Uses the Browser Run API; does not require Node.js or a Chrome binary locally, but requires Cloudflare credentials and service access. You prefer a hosted browser service and can use its credentials and access model.
Gotenberg or Chrome The Laravel PDF introduction lists them among drivers supporting modern CSS features. The cited pages do not establish a performance ranking. Compare their deployment and operational requirements with your environment before choosing.
WeasyPrint The introduction describes it as strong for CSS Paged Media. Your document depends on paged-media styling.
DOMPDF The introduction positions it for simpler layouts; the PDF guide says it does not execute JavaScript. Your output does not need JavaScript and its layout suits the driver.

These descriptions are from Laravel PDF v2’s introduction and installation and setup guide. They are not a benchmark: choose based on CSS and JavaScript needs, deployment dependencies, and whether your team wants to operate a renderer or use a hosted service.

Validate input and control browser access

Spatie explicitly makes the caller responsible for validating HTML and URLs passed to Browsershot. Treat rendering as a security boundary because it starts a browser process, not as a harmless string conversion.

  • Build documents from trusted templates and controlled data; do not pass arbitrary user-supplied markup directly to the renderer.
  • Validate and restrict URL inputs to destinations your application is intended to fetch. Consider what the rendering environment can reach before accepting a URL.
  • Keep the output path under application control rather than allowing a request to choose an arbitrary filesystem destination.
  • Check local asset access. Browser restrictions may prevent access to local files; review any change that disables browser security and limit it to trusted inputs.

For the validation responsibility and PDF options, see Browsershot v4 PDF creation; local-resource customization is covered in the Laravel PDF setup guide.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common rendering failures

Node, Puppeteer, or Chrome cannot be found

Check installed versions against Node.js 22.0+ and Puppeteer 23.0+, verify the browser binary exists in the generating environment, and configure paths using the Browsershot setup options if discovery fails. Review the requirements guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Images, fonts, or styles are missing

Confirm the browser process can reach the asset URLs or local resources and that permissions and browser restrictions permit access. If considering a security-setting change to allow local resources, assess the risk and use it only with trusted inputs.

The PDF does not reflect JavaScript-rendered content

Use a browser-based driver when the page depends on JavaScript. Laravel PDF’s v2 documentation specifically states that DOMPDF does not execute JavaScript; verify the selected driver’s behavior rather than assuming all drivers render alike.

It works locally but fails after deployment

Compare the actual PHP, Laravel, Node.js, Puppeteer, browser, operating system, permissions, and container setup between environments. The documented version requirements alone do not establish compatibility with every deployment.

Or skip the browser setup

If your task is capturing a website screenshot rather than generating a Laravel PDF from a Blade view, ScreenshotNeo offers a one-call screenshot API. It is not a replacement for this Browsershot PDF workflow; it returns a screenshot or PDF of a URL.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for the request options. Before capture, it accepts cookie or consent banners and removes 60+ known consent platforms, newsletter popups, and chat widgets; these steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and each response identifies the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 shots a month without a card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Frequently Asked Questions

Can Browsershot render HTML without loading a URL?

Yes. Pass the HTML string to `Browsershot::html()` and save it with `savePdf()`, as shown above.

Can I use Laravel PDF if I do not want a local Node.js and Chrome installation?

Its Cloudflare driver uses the Browser Run API and does not require those binaries locally, but it requires Cloudflare credentials and service access.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.