---
title: "Convert HTML & Markdown to PDF API"
slug: convert-html-markdown-to-pdf
url: https://apyhub.com/sarvasoft/service/convert-html-markdown-to-pdf
provider: SARVASOFT OPC PRIVATE LIMITED
categories: [Document Intelligence Kit, Output Kit, Media Kit]
tags: [pdf-conversion, html-to-pdf, markdown-to-pdf, document-generation, web-to-pdf]
auth: api_key
version: 2.0.0
service_type: sync
endpoints: 1
atoms: 16
mcp: true
---

# Convert HTML & Markdown to PDF API

HTML and Markdown to PDF API: send HTML, Markdown or a URL and get a PDF with headers, page numbers, watermark and password. Free tier, no card.

## Endpoints

| Method | URL | Description | Atoms |
| --- | --- | --- | --- |
| POST | `https://api.eu.apyhub.com/sarvasoft/convert-html-markdown-to-pdf/pdf/converter` | What it does Renders HTML, Markdown or a web page to a PDF in Chromium. Set the page layout, header… | 16 |

## Endpoint reference

### Convert content to PDF

`POST https://api.eu.apyhub.com/sarvasoft/convert-html-markdown-to-pdf/pdf/converter` · 16 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `url` | body | string (uri) | no | Public web page to load and render. Must be http or https. Provide exactly one of html, markdown or url. Example: `https://example.com`. |
| `html` | body | string | no | Raw HTML to render. Provide exactly one of html, markdown or url. Example: `<h1>Invoice #1042</h1><p>Total: $129.99</p>`. |
| `scale` | body | number | no | Render scale. Typical range 0.1 to 2. Default: `1`. Example: `1`. |
| `title` | body | string | no | Document title property. Example: `Invoice 1042`. |
| `width` | body | string or number | no | Custom page width, as pixels or a CSS unit. Overrides page_format. Example: `800px`. |
| `author` | body | string | no | Document author property. Example: `ACME Ltd`. |
| `height` | body | string or number | no | Custom page height, as pixels or a CSS unit. Example: `1200px`. |
| `cookies` | body | array of object | no | Cookies set in the browser before loading the page. Example: `[{"name":"session","value":"abc123","domain":"example.com"}]`. |
| `creator` | body | string | no | Document creator property. Example: `ACME Billing`. |
| `scripts` | body | array of string | no | Inline scripts or script URLs to run before rendering. Example: `["document.body.classList.add('print')"]`. |
| `subject` | body | string | no | Document subject property. Example: `Billing`. |
| `timeout` | body | integer | no | Load and render timeout in milliseconds. Default: `30000`. Example: `30000`. |
| `compress` | body | boolean | no | Compress embedded images. Default: `false`. Example: `true`. |
| `filename` | body | string | no | Name of the PDF. Default: `document.pdf`. Example: `invoice-1042.pdf`. |
| `keywords` | body | array of string | no | Document keywords property. Example: `["invoice","billing"]`. |
| `markdown` | body | string | no | Markdown to convert to HTML and render. Provide exactly one of html, markdown or url. Example: `# Report

- First point`. |
| `password` | body | string | no | Password needed to open the PDF. Example: `Invoice2026!`. |
| `producer` | body | string | no | Document producer property. Example: `ACME Billing`. |
| `auth_type` | body | string | no | Login used when loading url. One of: none, basic, bearer. Default: `none`. Example: `basic`. |
| `landscape` | body | boolean | no | Render in landscape orientation. Default: `false`. Example: `false`. |
| `page_size` | body | string | no | Paper size name, if different from page_format. Example: `Letter`. |
| `style_url` | body | string | no | Public URL of a CSS file to load before rendering. Example: `https://example.com/print.css`. |
| `custom_css` | body | string | no | CSS injected into the page before rendering. Example: `body { font-family: Arial, sans-serif; }`. |
| `margin_top` | body | string | no | Top margin as a CSS length, for example 1cm or 10mm. Default: `1cm`. Example: `1cm`. |
| `media_type` | body | string | no | CSS media type to emulate. One of: screen, print. Default: `screen`. Example: `print`. |
| `script_url` | body | string | no | Public URL of a JavaScript file to load before rendering. Example: `https://example.com/chart.js`. |
| `wait_until` | body | string | no | When the page counts as loaded. One of: load, domcontentloaded, networkidle, networkidle0, networkidle2. Default: `networkidle`. Example: `networkidle`. |
| `margin_left` | body | string | no | Left margin as a CSS length. Default: `1cm`. Example: `1cm`. |
| `page_format` | body | string | no | Paper size, for example A4 or Letter. Default: `A4`. Example: `A4`. |
| `page_ranges` | body | string | no | Pages to keep, for example 1-3,5. Example: `1-3,5`. |
| `margin_right` | body | string | no | Right margin as a CSS length. Default: `1cm`. Example: `1cm`. |
| `extra_headers` | body | object | no | Extra HTTP headers sent when loading url. Example: `{"Accept-Language":"en-GB"}`. |
| `margin_bottom` | body | string | no | Bottom margin as a CSS length. Default: `1cm`. Example: `1cm`. |
| `response_mode` | body | string | no | How the PDF is returned: binary (the file itself), base64, json (base64 plus size and creation time) or url (a temporary download link). One of: binary, base64, json, url. Default: `binary`. Example:… |
| `sanitize_html` | body | boolean | no | Clean the HTML before rendering. Can remove scripts and styles. Default: `false`. Example: `false`. |
| `watermark_text` | body | string | no | Text stamped on every page. Example: `DRAFT`. |
| `custom_metadata` | body | object | no | Extra key/value properties to write into the PDF. Example: `{"flow":"billing"}`. |
| `footer_template` | body | string | no | HTML printed at the bottom of every page. Example: `<div style='font-size:10px'>Confidential</div>`. |
| `header_template` | body | string | no | HTML printed at the top of every page. Example: `<div style='font-size:10px'>ACME Ltd</div>`. |
| `watermark_color` | body | string | no | Watermark text colour as hex. Default: `#000000`. Example: `#FF0000`. |
| `auth_credentials` | body | string | no | Login value for auth_type: username:password for basic, the token for bearer. Example: `user:secret`. |
| `compress_quality` | body | integer | no | Image quality after compression. Example: `70`. |
| `print_background` | body | boolean | no | Print CSS background colours and images. Default: `true`. Example: `true`. |
| `wait_for_timeout` | body | integer | no | How long to wait for the selector or function, in milliseconds. Example: `5000`. |
| `auto_page_numbers` | body | boolean | no | Add page numbers to every page. Default: `false`. Example: `true`. |
| `compression_level` | body | string | no | How strongly to compress when compress is true. One of: low, medium, high. Default: `medium`. Example: `high`. |
| `page_number_color` | body | string | no | Page number colour as hex. Default: `#444444`. Example: `#444444`. |
| `wait_for_function` | body | string | no | JavaScript expression to wait for until it is true. Example: `window.chartsReady === true`. |
| `wait_for_selector` | body | string | no | CSS selector to wait for before rendering. Example: `#report-ready`. |
| `watermark_opacity` | body | number | no | Watermark text opacity. Default: `0.15`. Example: `0.15`. |
| `execute_javascript` | body | boolean | no | Run the page's JavaScript before rendering. Default: `true`. Example: `true`. |
| `watermark_position` | body | string | no | Watermark position, for example center, top-left or bottom-right. Default: `center`. Example: `center`. |
| `watermark_rotation` | body | integer | no | Watermark text angle in degrees. Default: `45`. Example: `45`. |
| `watermark_font_size` | body | integer | no | Watermark text size. Default: `40`. Example: `40`. |
| `watermark_image_url` | body | string | no | Public URL of an image stamped on every page. Example: `https://example.com/logo.png`. |
| `page_number_template` | body | string | no | Page number text. Default: `{{page}} / {{totalPages}}`. Example: `{{page}} / {{totalPages}}`. |
| `prefer_css_page_size` | body | boolean | no | Use the page size from CSS @page when the page sets one. Default: `false`. Example: `false`. |
| `page_number_alignment` | body | string | no | Page number position. One of: left, center, right. Default: `center`. Example: `right`. |
| `page_number_font_size` | body | string | no | Page number font size. Default: `10px`. Example: `10px`. |
| `watermark_image_scale` | body | number | no | Image watermark size factor. Default: `1`. Example: `0.4`. |
| `watermark_image_opacity` | body | number | no | Image watermark opacity. Default: `0.15`. Example: `0.15`. |
| `watermark_image_rotation` | body | integer | no | Image watermark angle in degrees. Default: `45`. Example: `0`. |

#### Quickstart

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

```bash
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.

```json
{
  "filename": "invoice-1042.pdf",
  "size": 770,
  "created_at": "2026-01-15T10:30:00Z",
  "pdf_base64": "JVBERi0xLjcKJb/3ov4KMSAwIG9iago8PCAvVHlwZSAvT2JqU3RtIC9MZW5ndGggMjI5..."
}
```

## About

## 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](https://apyhub.com/apyhub/service/merge-files-to-pdf) can add attachments, and the [Extract PDF Content API](https://apyhub.com/sarvasoft/service/extract-pdf-content) reads the text back for indexing.

AI agents can call it through ApyHub MCP.

## Usage

Base URL: `https://api.eu.apyhub.com` (default region — see
`GET https://apyhub.com/api/public/regions` for the rest).

Authenticate with an ApyHub API key in the `apy-token` header.
Full docs and a live playground: https://apyhub.com/sarvasoft/service/convert-html-markdown-to-pdf
