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

Use Dompdf’s loadHtmlFile() to load a page, then render and stream the resulting PDF. Enable remote resources only when the page needs external images or stylesheets—and remember that Dompdf renders HTML with its own CSS support, not a live browser view.

Convert a URL to a PDF with Dompdf

Install Dompdf with Composer, load Composer’s autoloader, and pass the URL to loadHtmlFile(). This example sends the generated PDF to the browser:

  1. Install the package in your PHP project:

    composer require dompdf/dompdf

  2. Save this as a PHP endpoint, such as pdf.php, and replace the example URL with the page you intend to render:

    <?php
    declare(strict_types=1);
    
    require __DIR__ . '/vendor/autoload.php';
    
    use DompdfDompdf;
    use DompdfOptions;
    
    $url = 'https://example.com/page';
    
    $options = new Options();
    // Enable only if the page needs remote images or CSS.
    $options->set('isRemoteEnabled', true);
    
    $dompdf = new Dompdf($options);
    $dompdf->loadHtmlFile($url);
    $dompdf->setPaper('A4', 'portrait');
    $dompdf->render();
    $dompdf->stream('page.pdf', ['Attachment' => true]);
  3. Request the endpoint. With Attachment => true, the browser offers the PDF as a download. Set it to false if you want the browser to try to display the PDF inline.

    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.
    #1 Best Overall
    Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
    • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
    • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
    • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
    • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
    • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

The core sequence is loadHtmlFile(), render(), then stream(). The official Dompdf README documents installation and this lifecycle; check documentation for the installed release because the README describes latest stable code and may differ from a released package.

Save the PDF instead of streaming it

To write the rendered PDF to a server-side file, replace the final stream() call with:

$pdf = $dompdf->output();
file_put_contents(__DIR__ . '/page.pdf', $pdf);

Choose a destination the PHP process is allowed to write to, and do not let an untrusted request choose arbitrary filesystem paths.

Remote resources: images, CSS, and security

Dompdf’s remote access option is disabled by default. Set isRemoteEnabled only when external resources are required. Fetching web-based resources also requires PHP cURL or allow_url_fopen to be available. If either the option or the PHP capability is missing, remote images or stylesheets may not appear in the PDF. See the Dompdf usage guidance and Options source.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
  • Limit the URLs the service can process. Avoid accepting arbitrary user-supplied URLs or HTML in a process that can reach internal services or sensitive files. Restrict permitted remote hosts where your installed version and configuration allow it.

  • Keep local file access bounded. Dompdf uses configured chroot paths to constrain local file references. Do not widen those paths casually.

  • Leave embedded PHP disabled for untrusted documents. It is disabled by default; enabling it for arbitrary content creates unnecessary risk.

  • Review package security before deployment. Check the current Dompdf security advisories and use a patched dependency version. The advisory index includes advisories dated July 20, 2026, and identifies Dompdf 3.1.6 as a patched version for several listed issues; verify the specific advisory and your installed release rather than treating that version as a universal fix.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    Rank #3
    Sale
    Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
    • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
    • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
    • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
    • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
    • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Paper size, orientation, and page appearance

setPaper() accepts a paper size and orientation. The example uses A4 portrait; for landscape, change the call to $dompdf->setPaper('A4', 'landscape');. Select the paper size that fits the intended output, then test long pages and page breaks with the actual content.

Dompdf is mostly CSS 2.1 compliant, with selected CSS3 support. It does not support Flexbox or CSS Grid, table rows cannot split across pages, and raw inline SVG has restrictions. Pages relying on these features may need simpler HTML and CSS or a different rendering approach. These limitations mean a PDF should not be assumed to match the page shown in a browser.

Why remote images or stylesheets are missing

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

Operational notes for repeated conversions

Create a new Dompdf instance for each document. The README warns that parser and rendering artifacts may persist across renders, so reusing an instance can affect later output. For a batch conversion job, construct and configure a fresh instance inside each document’s processing step.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Or skip the browser setup

If you need a browser-based page capture rather than Dompdf’s HTML rendering, ScreenshotNeo provides a screenshot API and MCP server. It accepts a URL and returns PNG, JPEG, WebP, or PDF; cookie banners, newsletter popups, and chat widgets are removed before the shot, and bot checks, blank pages, timeouts, failed loads, and cache hits are not billed. Its MCP server includes tools for AI agents, and the free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000.

Example cURL call (replace the URL and use your API key):

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/page -o shot.webp

See the ScreenshotNeo API documentation for request options. Sign up free for 1,000 screenshots a month with no card.

Frequently Asked Questions

Can Dompdf produce a PDF identical to the browser page?

No such fidelity is established: Dompdf renders HTML using its own CSS support, and unsupported layout features can change the result.

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

Does Dompdf need a browser installed?

The described Dompdf workflow loads HTML into its renderer; it does not use a browser-based capture.

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.