The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
PHP cURL fetches HTML; it does not convert HTML into PDF. To turn a page into a PDF, retrieve the HTML with cURL, check both the transfer result and HTTP status, then pass the HTML string to a renderer such as Dompdf. Dompdf’s basic flow is loadHtml(), render(), then output() to save the PDF bytes or stream() to send them to a browser.
What PHP cURL does—and what creates the PDF
cURL is the fetching step: it makes an HTTP request and, with CURLOPT_RETURNTRANSFER enabled, gives your PHP code the response body as a string. A separate HTML-to-PDF renderer interprets that string and produces PDF bytes. In this example, Dompdf is the renderer.
That distinction matters when troubleshooting. A successful HTTP response does not guarantee a PDF, and a failed HTTP status is not necessarily a cURL transfer failure. Check the transfer result, inspect the status code, and only then send the HTML to the renderer.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Install Dompdf and prepare the PHP environment
Install Dompdf in a Composer-managed project using its package name, dompdf/dompdf. The project documentation lists PHP and extension requirements, including DOM and mbstring, along with library dependencies. Check the requirements for the exact release you install rather than assuming every server has the necessary extensions.
#1 Best Overall
- EDIT text, images & designs in PDF documents. ORGANIZE PDFs. Convert PDFs to Word, Excel & ePub.
- READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.
- CREATE, COMBINE, SCAN and COMPRESS PDFs
- FILL forms & Digitally Sign PDFs. PROTECT and Encrypt PDFs
- LIFETIME License for 1 Windows PC or Laptop. 5GB MobiDrive Cloud Storage Included.
The example below expects Composer’s autoloader at vendor/autoload.php, outbound HTTPS access from the PHP process, and permission for PHP to write the destination file. It requests a URL and converts the returned response body; it does not execute JavaScript or reproduce a browser session.
Fetch HTML with cURL and save a PDF with Dompdf
This complete example checks for a transport failure separately from an HTTP error status, uses a bounded connection and total timeout, and saves the rendered PDF beside the PHP file.
<?php
require __DIR__ . '/vendor/autoload.php';
use DompdfDompdf;
$url = 'https://example.com/page';
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_USERAGENT => 'HTML-to-PDF/1.0',
]);
$html = curl_exec($ch);
$curlError = curl_error($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($html === false) {
throw new RuntimeException('cURL transfer failed: ' . $curlError);
}
if ($status < 200 || $status >= 300) {
throw new RuntimeException('Unexpected HTTP status: ' . $status);
}
$dompdf = new Dompdf();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$pdf = $dompdf->output();
$outputPath = __DIR__ . '/page.pdf';
if (file_put_contents($outputPath, $pdf) === false) {
throw new RuntimeException('Could not write PDF to: ' . $outputPath);
}
echo 'Saved PDF to ' . $outputPath . PHP_EOL;
Use a URL you control or are authorized to fetch. The timeout values are example limits, not requirements: choose values suitable for your network and document size. CURLOPT_FOLLOWLOCATION allows cURL to follow redirects; remove it if your application should reject redirects and validate the destination before making a request.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsSend the PDF to a browser instead of writing a file
If the application should return a download response, render the document and use Dompdf’s stream() method instead of output() and file_put_contents():
$dompdf->render();
$dompdf->stream('page.pdf', ['Attachment' => true]);
Call stream() before outputting page text or whitespace; prior output can interfere with the response headers used for a PDF download.
Rank #2
- Edit PDFs with Ease. Modify text, images, and layouts directly within your PDF documents.
- Convert & Organize. Export PDFs to Word, Excel, or ePub, and organize files with ease.
- Read & Annotate. Enjoy intuitive reading modes and powerful tools to comment, highlight, and mark up PDFs.
- Create & Manage PDFs. Create new PDFs, combine multiple files, scan documents, and compress for easy sharing.
- Fill & Sign Forms. Complete forms and digitally sign documents with secure e-signature tools.
Use a local HTML string instead of fetching a URL
If the raw HTML already exists in your application, there is no need to call cURL. Pass the string directly to Dompdf:
$html = '<h1>Invoice</h1><p>Example content</p>';
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
file_put_contents(__DIR__ . '/invoice.pdf', $dompdf->output());
This is the right path for generated markup, such as an invoice template populated by your application. cURL is useful only when the input must first be retrieved over HTTP.
Choose paper, orientation, and layout for the content
setPaper() accepts the paper size and orientation; the example selects A4 portrait. Choose a different size or landscape orientation when the document’s content requires it. Check the rendered output with representative pages: long tables, wide content, page breaks, fonts, and image sizing can behave differently from a browser.
Dompdf’s project documentation describes its CSS support as limited and specifically notes that flexbox and CSS Grid are not supported. A page relying on those layout systems may not match its browser appearance. Prefer layout constructs supported by your installed renderer version, or use a rendering approach based on a browser engine when your template depends on browser-level CSS behavior.
Load images and stylesheets safely
Dompdf restricts access to remote and local resources. Remote images and stylesheets require the isRemoteEnabled option, and PHP must have cURL or allow_url_fopen available for URL fetching. Local files must be within the configured chroot paths.
Rank #3
- Create and edit PDFs. Collaborate with ease. E-sign documents and collect signatures. Get everything done in one app, wherever you go.
- Edit text and images without jumping to another app.
- E-sign documents or request e-signatures on any device. Recipients don’t need to log in to e-sign.
- Convert PDFs to editable Microsoft Word, Excel, or PowerPoint documents.
- Share PDFs for collaboration. Commenting features make it easy for reviewers to comment, mark up, and annotate.
Enable remote access only when the document needs it. Keep local file access constrained, and avoid rendering untrusted HTML with broad network or filesystem access: markup or resource references can cause the renderer to access resources beyond the intended document. Treat the HTML, URLs, and files a renderer can reach as part of your application’s security boundary.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Alternatives when Dompdf is not the right fit
Renderer choice depends on the HTML and CSS your templates use, the runtime and extensions available on your server, resource-loading policy, and how closely output must match a browser. Test representative documents rather than assuming any renderer handles every site layout.
- Dompdf: a direct fit when you have an HTML string and its CSS capabilities meet the template’s needs. Its documentation calls out the lack of flexbox and CSS Grid support.
- TCPDF’s current project documentation: describes
tc-lib-pdfas rendering a subset of HTML and CSS directly, without a browser engine. Verify that its supported subset covers your document. - wkhtmltox: PHP’s
wkhtmltoxmanual describes libwkhtmltox as using QtWebKit. Whether that is suitable depends on your deployment environment and the rendering behavior you need.
These are different trade-offs, not a universal ranking. Compare them against the actual templates you need to render and the PHP environment where the code will run.
Or skip the browser setup
If the input is a public page URL and you need a screenshot or PDF rather than a PDF rendered from a raw HTML string, ScreenshotNeo can return a capture with one request. It is a website screenshot API and MCP server by Yorker Media; it does not replace Dompdf for converting an arbitrary HTML string supplied by your application.
For example, use PHP cURL to request a PDF capture of a page:
Rank #4
- Perfect Adobe Acrobat Pro alternative – lifetime license for Windows 10 and 11.
- EDIT text, images, pages, hyperlinks, designs in PDF documents. ORGANIZE PDFs.
- READ and Comment on PDFs – Intuitive reading modes & document commenting and mark up tools!
- CREATE, COMBINE, SCAN and COMPRESS PDFs.
- FILL forms & Digitally Sign PDFs. Work with Digital certificates
<?php
$url = 'https://stripe.com';
$query = http_build_query([
'access_key' => 'YOUR_API_KEY',
'url' => $url,
'format' => 'pdf',
]);
$ch = curl_init('https://api.screenshotneo.com/v1/shot?' . $query);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 90,
]);
$pdf = curl_exec($ch);
$error = curl_error($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($pdf === false) {
throw new RuntimeException('Screenshot request failed: ' . $error);
}
if ($status < 200 || $status >= 300) {
throw new RuntimeException('Unexpected API status: ' . $status);
}
file_put_contents(__DIR__ . '/page.pdf', $pdf);
See the ScreenshotNeo API documentation for request options. Cookie and consent banners, newsletter popups, and chat widgets are removed before capture, and each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing; responses identify the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000, and every feature is available on every plan. Sign up free for 1,000 screenshots a month with no card.
Troubleshooting common failures
cURL returns false
A false result means the transfer failed. Read curl_error() before closing the handle, as in the example. Check DNS resolution, outbound network access, TLS configuration, the destination URL, and the connection timeout. Do not treat an empty string as the same thing as false: an empty response may be a successful transfer with no body.
The page returns 404 or another non-2xx status
cURL can complete a transfer even when the server responds with an HTTP error. That is why the example checks CURLINFO_HTTP_CODE independently after checking the transfer result. Verify the URL and access permissions, then decide whether your application should reject that status or handle the returned error page explicitly.
The PDF is blank or missing page content
First inspect the fetched HTML string and confirm that it contains the content you expect. A URL may return an error page, a minimal shell that relies on JavaScript, or markup different from what a browser shows. cURL fetches the HTTP response; it does not run the page’s JavaScript. If content appears only after client-side rendering, use an input or rendering approach that produces the needed HTML before conversion.
Images or stylesheets disappear
Check whether resources are remote or local. Remote resource loading requires the appropriate Dompdf option and URL-fetch support in PHP. Local resources must be reachable within the configured chroot. Also confirm that the HTML uses valid resource paths and that the PHP process can access them.
The output layout differs from the browser
Check the document for unsupported CSS, especially flexbox or Grid, and test the template with the chosen paper size and orientation. If browser-specific layout fidelity is essential, compare a browser-engine-based option against the template instead of repeatedly adjusting unsupported CSS.
Best Value
- ALL-IN-ONE SOLUTION – read, edit, convert, merge and protect your PDF files
- MAXIMUM FUNCIONALITY – create interactive forms, compare PDFs, bates numbering, find and replace text or colors, convert documents, OCR engine, comment, highlight, fill out and print forms, document protection and others
- EASY TO INSTALL AND USE – well-structured user-interface, in-program instructions, free tech support whenever you need it
- GREAT VALUE FOR MONEY - why spend a fortune if you can have maximum functionality at a reasonable price - this also fits the requirements of companies very well
Writing the PDF fails
Confirm that the destination directory exists and is writable by the PHP process. Check the return value from file_put_contents() as shown, and ensure that your application is not trying to save an unexpectedly large document to a constrained filesystem.
Performance, reliability, and cost considerations
This workflow performs a network fetch followed by PDF rendering, so total request time includes both operations. Bound network waits with connection and total timeouts, and consider the maximum document size and execution limits of your PHP environment. Rendering complex or lengthy HTML can consume meaningful CPU and memory; test typical and largest expected documents in the deployment environment.
Recommended Free Tools
For repeated conversions, create a fresh Dompdf instance per document. The project documentation warns that rendering state may persist if a single instance is reused for multiple documents. If a request can be retried, make sure the application does not accidentally emit or save partial output as though it were a completed PDF. This implementation uses a PHP library rather than a per-conversion API, so its direct costs depend on your own server resources and hosting arrangement.
FAQ
Can cURL convert an HTML string without a URL?
No. cURL is for making transfers; if your application already has the HTML string, pass it directly to a renderer such as Dompdf and omit the fetch step.
Does this method render JavaScript-created page content?
No. The cURL request retrieves an HTTP response body; it does not run JavaScript in a browser.
Should I reuse one Dompdf object for a batch?
Use a new instance for each document because Dompdf’s project documentation warns that state can persist between renders.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
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.

