HTML to PDF

Convert HTML content, web pages, or HTML files to PDF format.

POSThttps://api.morphopdf.com/v1/convert/html-to-pdf

Authentication

AuthorizationBearer

Retrieve your API Key from Dashboard.

Request Body

Provide HTML content using one of the following methods (mutually exclusive).

fileFileOptional

HTML file uploaded via multipart/form-data.

urlstringOptional

Public URL of a web page to render as PDF. Full JavaScript support.

htmlstringOptional

Raw HTML string to convert to PDF.

Query Parameters

formatstringOptionalDefault: json

Response 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):

successboolean

Indicates whether the operation completed successfully.

messagestring

Human-readable status message.

fileNamestring

Name of the generated PDF document.

downloadUrlstring

Presigned URL to download the file. Valid for 1 hour.

processingTimeMsnumber

Time taken to process the conversion in milliseconds.

outputSizenumber

Size of the generated PDF in bytes.

originalSizenumber

Size of the original input in bytes.

compressionAppliedboolean

Whether compression was applied to the output.

compressionRatiostring | null

Compression ratio if compression was applied, null otherwise.

renderingModestring

Rendering mode used for the conversion (e.g. 'browser').

usedFallbackboolean

Whether a fallback rendering method was used.

conversionMethodstring

Conversion method used (e.g. 'puppeteer').

Binary Response

Add ?format=binary to receive the PDF directly with these headers:

  • Content-Type: application/pdf
  • Content-Disposition: attachment; filename="document.pdf"

Error Responses

StatusCodeDescription
400INVALID_INPUTNo HTML content provided (file, url, or html required)
400URL_NOT_ACCESSIBLEThe provided URL could not be accessed or loaded
401AUTHENTICATION_REQUIREDMissing or invalid API key
500PROCESSING_FAILEDInternal processing error
POST/v1/convert/html-to-pdf
curl -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
200OK
{
  "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"
}