Use Dompdf’s loadHtmlFile() to load a page, then render and stream the PDF. Dompdf converts HTML using its own CSS renderer; it does not behave like a full web browser, so complex layouts may need changes and browser-identical output is not guaranteed.
Convert a URL to PDF with Dompdf
Install Dompdf with Composer, load Composer’s autoloader, and give loadHtmlFile() the URL. Enable remote resources only when the document needs to retrieve external assets such as images or stylesheets.
-
Install the package in your PHP project:
composer require dompdf/dompdf -
Create a PHP file and use this example, replacing the URL with the page you want to convert:
<?php require __DIR__ . '/vendor/autoload.php'; use DompdfDompdf; use DompdfOptions; $options = new Options(); $options->set('isRemoteEnabled', true); // Needed only for remote images or CSS. $dompdf = new Dompdf($options); $dompdf->loadHtmlFile('https://example.com/page'); $dompdf->setPaper('A4', 'portrait'); $dompdf->render(); $dompdf->stream('page.pdf'); -
Run the script through your PHP web server. Dompdf sends the generated PDF to the response using
stream(). For a different page size or orientation, adjust the arguments tosetPaper().Recommended Free Tools
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.#1 Best Overall
The official Dompdf README documents Composer installation and the load-render-stream lifecycle. The Dompdf source accepts a filename or URL in loadHtmlFile(). Check the documentation for the version installed in your project; the README notes that its content may describe newer code than a released package.
When remote images or stylesheets are missing
Dompdf disables remote resource access by default. To retrieve web-hosted assets, set isRemoteEnabled to true and ensure PHP has either the cURL extension or allow_url_fopen enabled. The option applies to remote resources in the document; it is not required merely to render HTML that contains no externally fetched assets.
Rank #2
Local file references are subject to Dompdf’s configured chroot paths. Keep those paths as narrow as practical rather than broadening access just to make a resource load. See the Dompdf options source for the remote-access and file-access settings.
Security and reliability considerations
Do not trust arbitrary URLs
If a user can submit the URL or HTML to render, the process may be induced to request remote resources or read files within its permitted paths. Accept only URLs appropriate for your application, constrain which remote hosts are reachable where your installed version and configuration allow it, and retain the chroot boundary for local files.
Free tools Windows power users keep installed
One-click scans. No signup required.
Keep embedded PHP disabled
Dompdf’s embedded-PHP option is disabled by default. Do not enable it for untrusted documents; executing embedded code changes the security risk substantially. Consult the options documentation before changing security-related defaults.
Use one renderer instance per document
Create a fresh Dompdf instance for each PDF. The README warns that parser and rendering artifacts can persist across renders, so reusing an instance for multiple documents can produce unexpected results.
Rank #4
Check the installed release
Review the package version and its dependencies against Dompdf’s security advisories before deployment. The advisory index lists several advisories dated July 20, 2026 and identifies Dompdf 3.1.6 as a patched version for several listed issues; confirm which advisories apply to your version rather than assuming every installation is affected or covered.
What Dompdf can and cannot reproduce
Dompdf describes its CSS support as mostly CSS 2.1, with selected CSS3 features. It does not support Flexbox or CSS Grid, and table rows cannot split across pages. Raw inline SVG also has restrictions. A page built around these features may render differently or require simpler HTML and CSS.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesFor predictable output, use print-oriented markup and styles compatible with Dompdf, and verify the resulting PDF with representative pages. If the requirement is to capture what a browser displays—including browser layout behavior—Dompdf is not a browser-based screenshot tool, and its documentation does not promise browser-identical rendering.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If you need a browser-rendered capture or PDF rather than Dompdf’s HTML rendering, ScreenshotNeo is a website screenshot API with a PDF option. A single GET request can return an image or PDF. Its request options include PDF paper size, margins, landscape orientation and page ranges. Cookie banners, newsletter popups and chat widgets are removed before capture; bot checks, blank pages and failed loads are never billed. An MCP server lets AI agents use screenshot tools, and the free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.
See the ScreenshotNeo documentation for API parameters. 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.webp
Sign up for 1,000 free screenshots a month, with no card required.
Frequently Asked Questions
Can I save the generated PDF to a file instead of streaming it?
Yes. Call output() to obtain the rendered PDF bytes and write them with PHP’s file-writing functions, or use Dompdf’s file-saving API as documented for your installed version.
Does Dompdf run JavaScript on the source page?
The documented URL-loading and rendering workflow here does not establish browser-style JavaScript execution. Do not rely on client-side scripts to construct the page content Dompdf will render.
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.




