HTML to PDF
Convert HTML content, web pages, or HTML files to PDF format.
https://api.morphopdf.com/v1/convert/html-to-pdfAuthentication
Retrieve your API Key from Dashboard.
Request Body
Provide HTML content using one of the following methods (mutually exclusive).
fileFileOptionalHTML file uploaded via multipart/form-data.
urlstringOptionalPublic URL of a web page to render as PDF. Full JavaScript support.
htmlstringOptionalRaw HTML string to convert to PDF.
Query Parameters
formatstringOptionalDefault: jsonResponse format. Use 'binary' to receive the PDF directly, or 'json' (default) to receive metadata with a download URL.
URL Rendering
When using the url parameter, the page is rendered in a headless browser with full JavaScript support. This allows dynamic content, SPAs, and JavaScript-rendered pages to be captured accurately.
Response
When using format=json (default):
successbooleanIndicates whether the operation completed successfully.
messagestringHuman-readable status message.
fileNamestringName of the generated PDF document.
downloadUrlstringPresigned URL to download the file. Valid for 1 hour.
processingTimeMsnumberTime taken to process the conversion in milliseconds.
outputSizenumberSize of the generated PDF in bytes.
originalSizenumberSize of the original input in bytes.
compressionAppliedbooleanWhether compression was applied to the output.
compressionRatiostring | nullCompression ratio if compression was applied, null otherwise.
renderingModestringRendering mode used for the conversion (e.g. 'browser').
usedFallbackbooleanWhether a fallback rendering method was used.
conversionMethodstringConversion method used (e.g. 'puppeteer').
Binary Response
Add ?format=binary to receive the PDF directly with these headers:
Content-Type: application/pdfContent-Disposition: attachment; filename="document.pdf"
Error Responses
| Status | Code | Description |
|---|---|---|
| 400 | INVALID_INPUT | No HTML content provided (file, url, or html required) |
| 400 | URL_NOT_ACCESSIBLE | The provided URL could not be accessed or loaded |
| 401 | AUTHENTICATION_REQUIRED | Missing or invalid API key |
| 500 | PROCESSING_FAILED | Internal processing error |
/v1/convert/html-to-pdfcurl -X POST "https://api.morphopdf.com/v1/convert/html-to-pdf?format=binary" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "url=https://example.com" \
--output webpage.pdf{
"success": true,
"message": "File processed successfully",
"fileName": "document.pdf",
"downloadUrl": "https://files.morphopdf.com/sessions/abc123/output/document.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=3600&...",
"processingTimeMs": 1800,
"outputSize": 256000,
"originalSize": 15360,
"compressionApplied": false,
"compressionRatio": null,
"renderingMode": "browser",
"usedFallback": false,
"conversionMethod": "puppeteer"
}