To convert a live URL to PDF in PHP, use Spatie Browsershot for a concise PHP API, chrome-php/chrome for direct control of Chrome from PHP, or Chrome’s headless command line if invoking a browser executable suits your deployment. All three rely on Chrome rendering the page; choose based on how much browser lifecycle and print control your application needs.
Choose a PHP-to-PDF approach
| Approach | PHP integration | Browser setup | Print controls documented | Best fit |
|---|---|---|---|---|
| Browsershot | Concise URL-to-file API | Puppeteer controls headless Chrome | URL, HTML string, or local HTML file; consult current docs for detailed options | A straightforward PHP-facing interface |
| chrome-php/chrome | Direct browser and page API | Chrome or Chromium controlled from PHP | Paper dimensions, margins, scale, orientation, CSS page size, backgrounds, headers and footers, and streaming | Fine-grained page or browser control |
| Chrome CLI | PHP must launch the executable | Installed Chrome invoked in headless mode | Print to PDF, omit headers and footers, set a capture timeout, and use a virtual-time budget | A command-line workflow when process management is suitable |
Compatibility details move with package releases. The Browsershot version 5.4.0 listing checked on 2026-10-03 requires PHP ^8.2; its release date was 2026-05-26. The chrome-php/chrome README lists PHP 7.4–8.5 and Chrome/Chromium 65 or later. Confirm current requirements before installing: Packagist Browsershot package metadata, Browsershot README, and the Chrome PHP README.
As an Amazon Associate I earn from qualifying purchases.
Use Browsershot for a concise PHP API
Install the package with Composer, then pass the URL and a PDF filename to save():
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →composer require spatie/browsershot
<?php
require __DIR__ . '/vendor/autoload.php';
use SpatieBrowsershotBrowsershot;
Browsershot::url('https://example.com')
->save(__DIR__ . '/example.pdf');
Browsershot renders through Puppeteer controlling headless Chrome; it is not a PHP-only renderer. The project README identifies Puppeteer as a test-suite requirement and points to separate requirements documentation. Check its current setup instructions for the production environment rather than assuming that a test command fully installs the runtime: Browsershot README.
#1 Best Overall
The same package accepts an HTML string or a local HTML file as input. For URL conversion, use Browsershot::url() as shown; use the project documentation for the appropriate methods and options when the input is not a URL.
Use chrome-php/chrome for browser and print control
Install the library and create a browser, page, navigation, and PDF. Close the browser in a finally block so it is cleaned up if navigation or PDF generation throws an exception.
Rank #2
composer require chrome-php/chrome
<?php
require __DIR__ . '/vendor/autoload.php';
use HeadlessChromiumBrowserFactory;
$browser = (new BrowserFactory())->createBrowser();
try {
$page = $browser->createPage();
$page->navigate('https://example.com')->waitForNavigation();
$page->pdf(['printBackground' => true])
->saveToFile('/tmp/example.pdf');
} finally {
$browser->close();
}
The documented PDF options include orientation, whether to print backgrounds, whether CSS @page sizing takes precedence, margins, paper dimensions, scale, and header and footer templates. Output can be saved to a file or streamed to a PHP output stream. Header and footer templates can use classes for the date, title, URL, page number, and total page count. Consult the library README for the current option names and accepted values: Chrome PHP README.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteSet the Chrome executable and navigation wait
The library documents CHROME_PATH for selecting a Chrome executable, and also permits specifying an executable name in BrowserFactory. Its default navigation wait is for the load event; alternatives include DOM content loaded and network idle. A page that continues loading background resources or populates content after initial navigation may need a different event. Choose the wait condition to match the page, and handle timeouts in application code.
Use Chrome’s headless command line
When PHP can safely invoke an installed Chrome executable, Chrome’s CLI offers the shortest conversion command:
chrome --headless --print-to-pdf https://example.com/
Chrome saves output.pdf in the current working directory. Use --no-pdf-header-footer to omit Chrome’s generated date, URL, and page header and footer. The --timeout=5000 flag caps the wait at five seconds; it can also capture a slow page before it is ready. --virtual-time-budget is available to advance time-dependent page code during capture. See Chrome’s headless command-line reference (last updated 2024-10-21).
Rank #4
The command above is a shell example, not PHP process-launch code. If PHP starts Chrome, treat process execution as deployment-specific integration work: use safe argument handling, configure a process timeout, capture exit status and error output, and verify that the expected PDF was produced. Do not build a shell command by concatenating an untrusted URL.
Recommended Free Tools
Make the PDF match the page you need
- Choose readiness deliberately. A load event, DOM content loaded, network idle, or a bounded CLI timeout can produce different results. A short fixed wait trades completeness for speed; background requests can also make waiting for network idle unsuitable.
- Choose print layout explicitly. For
chrome-php/chrome, configure paper size or dimensions, margins, orientation, scale, background printing, and CSS@pagepreference as needed. The library also supports headers and footers. These settings determine print output; they do not guarantee every website will paginate identically. - Account for dynamic pages. Pages that reveal content after a delay or depend on time-sensitive scripts may need a suitable wait condition or virtual-time budget. A timeout only bounds waiting; it does not prove that the page is complete.
- Keep output paths intentional. Use a writable destination and make it clear whether the generated PDF is temporary or should be retained. The examples use a local file path; the PHP library also documents streaming output.
Troubleshoot common conversion failures
| Symptom | Likely cause | What to check |
|---|---|---|
| Chrome cannot start | The executable is absent, inaccessible, or not the one the library is using. | Confirm Chrome or Chromium is installed and available to the PHP process. For chrome-php/chrome, check CHROME_PATH or the executable passed to BrowserFactory. |
| Composer refuses installation | The PHP version does not meet the package’s current requirement. | Check the live package metadata and your CLI/runtime PHP versions. Browsershot 5.4.0’s listing checked on 2026-10-03 specifies ^8.2; requirements may change. |
| PDF is blank or missing late content | Navigation completed before the page’s scripts or delayed content were ready. | Try a different documented navigation event for chrome-php/chrome, or use an appropriate CLI timeout or virtual-time budget. Longer waiting can increase latency and still cannot guarantee a site has finished updating. |
| Backgrounds or page sizing differ from expectations | Print options or CSS print rules do not match the intended layout. | Review printBackground, CSS @page preference, margins, paper size, orientation, and scale in the library’s current documentation. |
| CLI output is not where expected | Chrome writes output.pdf to its current working directory. |
Run from the intended directory or account for that working directory in the PHP process integration. |
| PHP hangs while invoking Chrome | The child process is waiting on a slow page or is not being managed with a suitable timeout. | Set a process-level timeout, collect exit status and error output, and choose a bounded page wait appropriate to the site. |
Or skip the browser setup
If you only need a URL-to-PDF API call, ScreenshotNeo returns a PDF from one GET request. For example, using cURL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.pdf
See the ScreenshotNeo API documentation for request options and output details. ScreenshotNeo accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. It also offers an MCP server with screenshot, page-info, and PDF tools for AI agents. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Visit ScreenshotNeo or sign up free.
Operational considerations
With either PHP library or the CLI, your application is responsible for the browser runtime and its lifecycle. Browser startup, page readiness, and PDF rendering all contribute to request time; no performance benchmark is established here. For a web request handler, set timeouts and decide whether long renders belong in a background job. For repeatable output, record the browser and package versions in your deployment and recheck package requirements when upgrading.
Rendering also depends on the target website’s current content, scripts, fonts, and print styles. Treat the produced PDF as a browser print result, not a guarantee that every live page will retain identical layout across environments.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Frequently Asked Questions
Can I convert HTML instead of a URL with Browsershot?
Yes. Browsershot accepts an HTML string or a local HTML file as well as a URL; consult its README for the corresponding input methods.
Can chrome-php/chrome send the PDF directly to a response?
Its documentation says PDF output can be streamed to a PHP output stream as well as saved to a file.
Quick Recap
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.




