The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Send a JSON POST request to https://api.html2pdf.app/v1/generate with your API key in the X-API-Key header. For a synchronous conversion, the successful response body is the PDF’s binary data: check the HTTP status before saving or streaming it. Html2Pdf.app’s PHP guide lists PHP 8.1 or newer and the PHP cURL extension as requirements. [Html2Pdf.app PHP guide; API documentation]
What you need before making the request
- PHP 8.1 or newer and the cURL extension enabled.
- An Html2Pdf.app API key, stored in a server-side environment variable or your framework’s secret store.
- A source for the PDF: either raw HTML or a publicly reachable URL, supplied in the required
htmlfield.
Keep the key on the server. Do not put it in browser JavaScript, public repositories, or client-side templates. The API is intended to be called from a backend, server-side script, or trusted job. [Html2Pdf.app PHP guide; API documentation]
Make a synchronous request and save the PDF
This plain PHP example converts a public URL and writes the returned PDF to document.pdf beside the script. Set HTML2PDF_API_KEY in the server environment before running it.
<?php
$apiKey = getenv('HTML2PDF_API_KEY');
if (!$apiKey) {
throw new RuntimeException('HTML2PDF_API_KEY is not set');
}
$payload = ['html' => 'https://www.example.com'];
$ch = curl_init('https://api.html2pdf.app/v1/generate');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'X-API-Key: ' . $apiKey,
],
]);
$pdf = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$error = curl_error($ch);
curl_close($ch);
if ($pdf === false || $statusCode < 200 || $statusCode >= 300) {
throw new RuntimeException($error ?: 'PDF generation failed; HTTP ' . $statusCode);
}
if (file_put_contents(__DIR__ . '/document.pdf', $pdf) === false) {
throw new RuntimeException('Could not write document.pdf');
}
The endpoint and header follow Html2Pdf.app’s PHP example. On synchronous success, treat the response as binary PDF content—not JSON or text. [Html2Pdf.app PHP guide; API documentation]
#1 Best Overall
Use raw HTML instead of a URL
Replace the payload’s value with your HTML string when the content is generated by your application:
$payload = ['html' => '<!doctype html><html><body><h1>Invoice</h1><p>Amount due: $25</p></body></html>'];
If your HTML references images, stylesheets, or fonts by URL, the rendering service must be able to reach those resources.
Return the PDF from a PHP controller
After performing the same request and status checks shown above, return the binary body with PDF headers. Do not send an upstream error response to the browser as though it were a PDF.
Rank #2
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="document.pdf"');
echo $pdf;
exit;
Use attachment instead of inline in the disposition value if you want the browser to download the file rather than display it. The API’s PHP guide demonstrates streaming a generated PDF from a backend response. [Html2Pdf.app PHP guide]
Choose synchronous or asynchronous conversion
| Mode | How the result arrives | Choose it when | Additional work |
|---|---|---|---|
| Synchronous | The request returns the PDF binary data after conversion. | Your PHP request can remain open until the PDF is ready. | Check the HTTP status, then save or stream the binary response. |
| Asynchronous callback | The initial request is accepted with 202 Accepted; the PDF arrives later in a JSON POST to your callback URL. |
You want to queue work rather than hold the originating request open. | Provide a reachable HTTPS webhook, handle retries idempotently, and base64-decode the callback’s document field. |
For asynchronous conversion, include callBackUrl in the JSON request. The API can also return an optional state unchanged, which you can use to associate the callback with the report, order, or job that started the conversion. A 202 means queued, not that the response body contains the PDF. Html2Pdf.app says failed callback deliveries can be attempted more than once and are retried up to three times before being marked failed, so make the handler safe to receive the same job more than once. [API documentation]
When the callback arrives, read its JSON body, take the base64-encoded document value, and decode it before saving or serving the PDF. Reject malformed data and avoid overwriting a completed result unexpectedly.
Request options that affect the PDF
The API accepts options for page layout, rendering, and PDF output. Supply only the values your document needs and test the result with representative content.
- Page dimensions:
format,landscape, or customwidthandheight. Documented formats include Letter, Legal, Tabloid, Ledger, and A0 through A6. - Margins: Set the four page margins individually.
- Rendering mode:
mediaselectsscreenorprintCSS. - Wait and scale:
waitForis documented from 0 to 10 seconds;scalefrom 0.1 to 2. - Page furniture and file naming: Header and footer templates and a
filenameare available. - Security: Password and permission fields are available for encrypted PDFs.
The service renders in headless Chromium and supports modern HTML, CSS, and JavaScript, but the output still depends on the selected CSS media mode, reachable resources, and when JavaScript finishes rendering. [API documentation]
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Or skip the browser setup
If your task is capturing a web page as an image or PDF rather than creating a PDF through Html2Pdf.app, ScreenshotNeo offers a one-call screenshot API. For example, this cURL request saves a screenshot of Stripe as WebP; create an API key and consult the ScreenshotNeo API documentation for request options.
Rank #4
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
- Cookie and consent banners, newsletter popups, and chat widgets are removed before capture; each of those steps can be turned off.
- Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers report the page verdict and billing status.
- An MCP server provides
take_screenshot,get_page_info, andcapture_pdftools for AI agents and MCP clients. - The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots.
Sign up for ScreenshotNeo’s free plan.
Troubleshooting common failures
| HTTP result or symptom | Likely cause | What to check |
|---|---|---|
400 |
The source URL cannot be accessed or a request parameter is invalid. | Confirm the URL is publicly reachable and check the names, types, and allowed values of request fields. |
401 |
The API key is missing or invalid. | Check that HTML2PDF_API_KEY is set and that the request sends it as X-API-Key. |
403 |
The account has reached a plan limit. | Review your account plan and notifications before retrying. |
500 |
An unhandled server error occurred. | Retry after a short delay; if repeated attempts are needed, increase the delay between them. |
| PDF is blank or styling is missing | The page, CSS, font, or image may not be reachable by the rendering service; CSS media choice or JavaScript timing may also change the result. | Check resource accessibility, choose the intended media mode, and adjust waitFor where appropriate. |
PHP cURL returns false |
A transport or connection error prevented a response. | Inspect curl_error() and server network/TLS configuration; do not treat an absent response as a PDF. |
Do not automatically retry 400, 401, or 403 responses before correcting the request, credentials, or account limit. Always distinguish a valid PDF response from an error response before returning bytes to a browser. [API documentation]
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Estimate usage and cost
Html2Pdf.app’s pricing page, checked October 3, 2026, lists these monthly plans. Credits reset on the first day of each month, and the service says each 5 MB chunk of generated PDF uses one credit. Confirm the current terms on the pricing page before budgeting or deploying, because plans and limits can change. [Html2Pdf.app pricing]
| Plan | Monthly price listed | Credits | Parallel conversions | PDF size limit |
|---|---|---|---|---|
| Free | $0 | 100 | 1 | Up to 1 MB |
| Startup | $9 | 1,000 | 3 | Unlimited |
| Standard | $25 | 5,000 | 10 | Unlimited |
| Scale | $39 | 10,000 | 20 | Unlimited |
The pricing page describes these as monthly plan figures; the credit charge is based on generated PDF size, so estimate from your actual output sizes and expected conversion volume rather than counting requests alone.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsFrequently Asked Questions
Can I call Html2Pdf.app directly from browser JavaScript?
No. Keep the API key on the server and call the endpoint from PHP or another trusted backend.
Does a 202 response contain the generated PDF?
No. It confirms the asynchronous job was accepted; the PDF is delivered later to the callback URL.
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.




