apyhub
Back
▣ DOCUMENT INTELLIGENCE KIT · OUTPUT KIT

Convert HTML & Markdown to PDF API

What it does

The Convert HTML & Markdown to PDF API turns HTML, Markdown or a web page into a PDF. Send one of html, markdown or url, and get the PDF back in a Chromium render that keeps your CSS and runs JavaScript.

Set the page with page_format (default A4), landscape, scale and the four margins (default 1cm). Add a repeating header_template and footer_template, or turn on auto_page_numbers. Stamp every page with watermark_text or watermark_image_url. Lock the file with a password of up to 20 characters. Shrink it with compress. Write title, author and keywords into the document properties.

For live pages, wait_until and wait_for_selector hold the render until content loads. cookies, extra_headers and auth_type reach pages behind a login. response_mode returns the PDF as a file by default. It can also return base64, JSON with size and time, or a temporary download link.

Teams use this HTML and Markdown to PDF API to generate invoices, account statements and reports with page numbers. Markdown input turns release notes and docs into PDFs, and URL input archives web pages. One HTML to PDF API with header and footer support replaces a separate stamping step.

After rendering, the Merge Files to PDF API can add attachments, and the Extract PDF Content API reads the text back for indexing.

AI agents can call it through ApyHub MCP.

POST
Convert content to PDF
https://api.eu.apyhub.com/sarvasoft/convert-html-markdown-to-pdf/pdf/converter

QUICKSTART

GUIDE

Quickstart

Convert a simple HTML invoice into a PDF and return it as base64.

curl -X POST "https://api.eu.apyhub.com/sarvasoft/convert-html-markdown-to-pdf/pdf/converter" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<html><body><h1>Invoice #1042</h1><p>Customer: Demo User</p><p>Total: $129.99</p></body></html>",
    "filename": "invoice-1042.pdf",
    "response_mode": "base64"
  }'

What you'll get back

Returns a JSON object with filename and pdf_base64 fields. filename is the suggested file name, and pdf_base64 is the generated PDF encoded as base64.

{
  "filename": "invoice-1042.pdf",
  "size": 770,
  "created_at": "2026-01-15T10:30:00Z",
  "pdf_base64": "JVBERi0xLjcKJb/3ov4KMSAwIG9iago8PCAvVHlwZSAvT2JqU3RtIC9MZW5ndGggMjI5..."
}
TRY ITLIVE · 16 ATOMS
Loading your default key…
The full key is used to call the gateway and stays in this tab — never sent to orbit or saved.
body*
body*

About this endpoint

What it does

Renders HTML, Markdown or a web page to a PDF in Chromium. Set the page layout, headers and footers, watermark, password and document properties, and pick how the PDF comes back.

Request Body

ParameterTypeDescription
htmlStringRequired if markdown and url are not set. Raw HTML to render. Max length 1500000 characters. Provide exactly one of html, markdown or url.
markdownStringRequired if html and url are not set. Markdown to convert to HTML and render. Max length 1500000 characters.
urlStringRequired if html and markdown are not set. Public web page to load and render. Must be http or https.
response_modeStringHow the PDF is returned. Allowed values: binary, base64, json, url. Default: binary.
filenameStringName of the PDF. Default: document.pdf. Max length 255 characters.
page_formatStringPaper size, for example A4 or Letter. Default: A4.
page_sizeStringPaper size name, if different from page_format. Max length 32 characters.
widthStringCustom page width, as pixels or a CSS unit (for example 800px, 21cm). Overrides page_format.
heightStringCustom page height, as pixels or a CSS unit.
landscapeBooleanRender in landscape orientation. Default: false.
scaleNumberRender scale. Typical range 0.1 to 2. Default: 1.
margin_topStringTop margin as a CSS length, for example 1cm or 10mm. Default: 1cm.
margin_bottomStringBottom margin. Default: 1cm.
margin_leftStringLeft margin. Default: 1cm.
margin_rightStringRight margin. Default: 1cm.
print_backgroundBooleanPrint CSS background colours and images. Default: true.
prefer_css_page_sizeBooleanUse the page size from CSS @page when the page sets one. Default: false.
page_rangesStringPages to keep, for example 1-3,5. Max length 64 characters.
media_typeStringCSS media type to emulate. Allowed values: screen, print. Default: screen.
header_templateStringHTML printed at the top of every page.
footer_templateStringHTML printed at the bottom of every page.
auto_page_numbersBooleanAdd page numbers to every page. Default: false.
page_number_templateStringPage number text. Default: {{page}} / {{totalPages}}. Max length 128 characters.
page_number_alignmentStringPage number position. Allowed values: left, center, right. Default: center.
page_number_colorStringPage number colour as hex. Default: #444444.
page_number_font_sizeStringPage number font size. Default: 10px.
watermark_textStringText stamped on every page. Max length 1024 characters.
watermark_font_sizeIntegerWatermark text size. Range: 1 to 500. Default: 40.
watermark_colorStringWatermark text colour as hex. Default: #000000.
watermark_opacityNumberWatermark text opacity. Range: 0 to 1. Default: 0.15.
watermark_rotationIntegerWatermark text angle in degrees. Range: 0 to 360. Default: 45.
watermark_positionStringWatermark position, for example center, top-left or bottom-right. Default: center.
watermark_image_urlStringPublic URL of an image stamped on every page. Max length 2048 characters.
watermark_image_scaleNumberImage watermark size factor. Range: 0.1 to 10. Default: 1.
watermark_image_opacityNumberImage watermark opacity. Range: 0 to 1. Default: 0.15.
watermark_image_rotationIntegerImage watermark angle in degrees. Range: 0 to 360. Default: 45.
passwordStringPassword needed to open the PDF. Max length 20 characters.
compressBooleanCompress embedded images. Default: false.
compression_levelENUMHow strongly to compress when compress is true. Allowed values: low, medium, high. Default: medium.
compress_qualityIntegerImage quality after compression. Range: 30 to 95.
titleStringDocument title property. Max length 100 characters.
authorStringDocument author property. Max length 100 characters.
subjectStringDocument subject property. Max length 100 characters.
keywordsString ArrayDocument keywords property.
creatorStringDocument creator property. Max length 100 characters.
producerStringDocument producer property. Max length 100 characters.
custom_metadataObjectExtra key/value properties to write into the PDF.
custom_cssStringCSS injected into the page before rendering.
style_urlStringPublic URL of a CSS file to load before rendering. Max length 2048 characters.
script_urlStringPublic URL of a JavaScript file to load before rendering.
scriptsString ArrayInline scripts or script URLs to run before rendering.
execute_javascriptBooleanRun the page's JavaScript before rendering. Default: true.
sanitize_htmlBooleanClean the HTML before rendering. Can remove scripts and styles. Default: false.
wait_untilENUMWhen the page counts as loaded. Allowed values: load, domcontentloaded, networkidle, networkidle0, networkidle2. Default: networkidle.
wait_for_selectorStringCSS selector to wait for before rendering. Max length 256 characters.
wait_for_functionStringJavaScript expression to wait for until it is true.
wait_for_timeoutIntegerHow long to wait for the selector or function, in milliseconds. Range: 0 to 300000.
timeoutIntegerLoad and render timeout in milliseconds. Range: 1000 to 180000. Default: 30000.
auth_typeENUMLogin used when loading url. Allowed values: none, basic, bearer. Default: none.
auth_credentialsStringLogin value for auth_type: username:password for basic, the token for bearer. Max length 2048 characters.
extra_headersObjectExtra HTTP headers sent when loading url.
cookiesObject ArrayCookies set in the browser before loading the page.

Response

Returns the PDF in the shape set by response_mode. In json mode, returns a JSON object with the file and its metadata.

ParameterTypeDescription
filenameStringName of the PDF.
sizeIntegerSize of the PDF in bytes.
created_atStringUTC timestamp when the file was created.
pdf_base64StringBase64-encoded PDF.

Notes

  • Provide exactly one of html, markdown or url.
  • binary returns the PDF file itself, not JSON. base64 returns only filename and pdf_base64. url returns file_url, expires_at and expires_in_seconds. The link needs no authentication and stops working after it expires.
  • The request body must be under 5 MB. Larger bodies return 413.
  • A render that runs past timeout returns 504.
  • url, style_url, script_url, scripts and watermark_image_url must be public addresses.
▣ COMMON ERRORS

Errors any endpoint can return

400bad_request

Required parameter missing or malformed body.

401unauthorized

API key missing, revoked, or not authorized for this service.

429rate_limited

Your plan's per-second rate exceeded. Retry with exponential backoff.

503upstream_busy

Backend temporarily unavailable. Try again in a few seconds.