Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk4 min

Convert a URL to a PDF in PHP with Dompdf

A practical Dompdf guide to loading a URL, rendering a PDF, enabling remote assets safely, and understanding layout limitations.
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 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.

  1. Install the package in your PHP project:

    composer require dompdf/dompdf
  2. 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');
  3. 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 to setPaper().

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

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.

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.

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

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.

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.

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

For 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.Support on Ko-Fi

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.

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

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.

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 *

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
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver 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.