---
title: "Markdown-to-PDF API"
canonical_url: "https://www.nutrient.io/guides/dws-processor/tools-and-api/markdown-to-pdf-api/"
md_url: "https://www.nutrient.io/guides/dws-processor/tools-and-api/markdown-to-pdf-api.md"
last_updated: "2026-05-22T20:57:56.534Z"
description: "Turn Markdown into professionally styled PDFs with built-in templates, syntax highlighting, GitHub Flavored Markdown (GFM) tables, and custom CSS — or bring your own HTML template for complete control."
---

# Markdown-to-PDF API

This guide demonstrates how to convert Markdown content into professionally styled PDF documents using the Markdown-to-PDF API. Whether you’re generating reports from documentation, turning README files into shareable PDFs, or building a content pipeline that outputs print-ready documents, this API handles the conversion for you — complete with syntax-highlighted code blocks, [GitHub Flavored Markdown](https://github.github.com/gfm/) (GFM) tables, and a choice of built-in templates or completely custom HTML and CSS.

[Try for Free](https://www.nutrient.io/guides/dws-processor/getting-started.md)

## Quick start

Send a JSON request with inline Markdown to get a PDF back:

### SHELL

### HTTP

## Sending raw Markdown

If you have a `.md` file and don’t need any options, send the file contents directly with the `text/markdown` content type:

### SHELL

### HTTP

## Using a built-in template with custom CSS

Select a template and override specific styles with the `css` parameter:

### SHELL

### HTTP

## Uploading assets

When your Markdown references local images or you want to include custom fonts or other files, use `multipart/form-data` to upload the Markdown file and assets together. Each uploaded file part becomes an asset that can be referenced by filename in the Markdown or in your CSS and HTML templates.

### SHELL

### HTTP

To combine asset uploads with template or CSS options, include a `data` part containing JSON:

### SHELL

### HTTP

## Custom HTML templates

For complete control over the output, provide an HTML template via the `html` part in a multipart request. The rendered Markdown body is inserted at the `{{content}}` placeholder inside your HTML.

### SHELL

### HTTP

A minimal custom HTML template looks as follows. The `{{content}}` placeholder is required and is where the rendered Markdown will be injected:

```html

<!DOCTYPE html>
<html>
<head>
  <style>
    @font-face {
      font-family: 'BrandFont';
      src: url('brand-font.woff2') format('woff2');
    }
    body {
      font-family: 'BrandFont', sans-serif;
      max-width: 800px;
      margin: 0 auto;
      padding: 40px;
    }
    h1 { color: #2c3e50; border-bottom: 2px solid #3498db; }

  </style>
</head>
<body>
  <header>
    <img src="header-bg.png" alt="Header" style="width:100%">
  </header>
  {{content}}
</body>
</html>

```

Asset files uploaded alongside the HTML template (fonts, images, stylesheets) can be referenced by their part name. When using an inline HTML template, the `css` parameter is ignored — all styling is controlled by the HTML.

## Supported Markdown features

The parser is [CommonMark](https://spec.commonmark.org/0.31.2/) compliant. All standard CommonMark syntax is supported:

- Headings (`#` through `######`)

- Paragraphs and line breaks

- Emphasis (`*italic*`, `**bold**`, `***bold italic***`)

- Links and images

- Inline code and fenced code blocks with syntax highlighting

- Block quotes

- Ordered and unordered lists

- Thematic breaks (`---`)

The following GFM features are also supported:

| Feature           | Syntax                                                                    |
| ----------------- | ------------------------------------------------------------------------- |
| Tables            | Pipe-delimited tables with column alignment                               |
| Strikethrough     | `~~deleted text~~`                                                        |
| Autolinks         | Bare URLs and email addresses become clickable                            |
| Task lists        | `- [x] done` / `- [ ] todo`                                               |
| Alerts            | `> [!NOTE]`, `> [!WARNING]`, `> [!TIP]`, `> [!IMPORTANT]`, `> [!CAUTION]` |
| Footnotes         | `[^1]` reference-style and `^[inline]` footnotes                          |
| Superscript       | `^superscript^`                                                           |
| Subscript         | `~subscript~`                                                             |
| Highlight         | `==highlighted text==`                                                    |
| Description lists | `Term` followed by `: Definition`                                         |

## Built-in templates

Select a template with the `template` parameter. When no template is specified, `built-in:default` is used.

### Report templates

Optimized for multipage documents, articles, and documentation.

| Template                 | Page                        | Description                                                                                                      |
| ------------------------ | --------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| `built-in:default`       | A4                          | GFM style. Arimo font, heading underlines, light gray table headers. Used when no template is specified.         |
| `built-in:minimal`       | A4, narrow margins          | Clean and lightweight. Carlito font, no heading borders, minimal decoration. Maximizes content area.             |
| `built-in:corporate`     | US Letter, one-inch margins | Professional business style. Navy headings and table headers. Suitable for formal business documents.            |
| `built-in:elegant`       | A4                          | Dense report style with blue accent headings. Dark table headers. Optimized for data-heavy reports.              |
| `built-in:executive`     | A4, one-inch margins        | Premium and polished. Generous whitespace, large title. Designed for presentation-quality reports.               |
| `built-in:nordic`        | A4                          | Scandinavian design with serif headings and sans-serif body. Blue accent on lower-level headings.                |
| `built-in:nordic-report` | A4                          | Dense Nordic style for data-heavy reports. Dark navy table headers, alternating row colors.                      |
| `built-in:technical`     | A4, tight margins           | Information-dense technical documentation. Tight line-height, prominent code blocks. Maximizes content per page. |

### Presentation templates

Larger text and more whitespace, optimized for executive briefings.

| Template                        | Page | Description                                                                            |
| ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
| `built-in:elegant-presentation` | A4   | Elegant scaled up for presentations. Larger body and title text. Blue accent headings. |
| `built-in:nordic-executive`     | A4   | Premium with large title, inverted code blocks (dark background, light text).          |
| `built-in:nordic-presentation`  | A4   | Nordic style scaled for projection. Large headings, dark navy table headers.           |

## Custom CSS

Override or extend the selected template’s styles with the `css` parameter. The custom CSS is appended after the template stylesheet:

```json

{
  "markdown": "# My Document\n\nStyled content here.",

  "template": "built-in:nordic",
  "css": "body { font-size: 12pt; } h1 { color: #e74c3c; } table th { background: #2c3e50; color: white; }"

}

```

When no template is specified, the CSS is appended after the default stylesheet. When using a custom HTML template (via the `html` multipart part), the `css` parameter is ignored.

## Page layout

The `layout` parameter controls page dimensions, orientation, and margins. If omitted, the template’s default layout is used.

```json

{
  "markdown": "# Landscape Report\n\nWide tables look better in landscape.",

  "layout": {
    "size": "Letter",
    "orientation": "landscape",
    "margin": { "top": 20, "right": 20, "bottom": 20, "left": 20 }
  }
}

```

| Option        | Type             | Default                                              | Description                                                                                                      |
| ------------- | ---------------- | ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| `size`        | String or object | `"A4"`                                               | A preset name (`"A4"`, `"Letter"`, `"Legal"`, `"A0"`–`"A8"`) or custom dimensions `{"width": mm, "height": mm}`. |
| `orientation` | String           | `"portrait"`                                         | `"portrait"` or `"landscape"`.                                                                                   |
| `margin`      | Object           | `{"top": 10, "right": 10, "bottom": 10, "left": 10}` | Page margins in millimeters. Each field must be >= 0.                                                            |

## Syntax highlighting

Fenced code blocks with a language identifier receive automatic syntax highlighting. Configure via `markdown_options.syntax_highlight`:

````json

{
  "markdown": "# Code Example\n\n```python\ndef greet(name):\n    return f'Hello, {name}!'\n```",

  "markdown_options": {
    "syntax_highlight": {
      "theme": "github"
    }
  }
}

````

| Option  | Type   | Default     | Description                                                                        |
| ------- | ------ | ----------- | ---------------------------------------------------------------------------------- |
| `theme` | string | `"onedark"` | Color theme name. Refer to the [dark themes](#dark-themes) and [light themes](#light-themes) options below. |

Set `syntax_highlight` to `false` to disable highlighting entirely.

### Dark themes

- `onedark` (default)

- `dracula`

- `monokai`

- `nord`

- `github-dark`

- `github-dark-dimmed`

- `gruvbox-dark`

- `catppuccin-mocha`

- `base16-ocean-dark`

- `ayu-dark`

- `ayu-mirage`

- `solarized-dark`

- `visual-studio-dark`

- `material-dark`

- `night-owl`

- `synthwave-84`

- `coldark-dark`

- `tokyonight-storm`

- `tokyonight-night`

- `kanagawa-wave`

- `kanagawa-dragon`

- `rose-pine`

- `rose-pine-moon`

- `nightfox`

- `nordfox`

- `carbonfox`

- `terafox`

- `duskfox`

- `everforest-dark`

- `oxocarbon-dark`

- `tomorrow-night`

- `zenburn`

### Light themes

- `github`

- `github-light`

- `inspired-github`

- `catppuccin-latte`

- `gruvbox-light`

- `solarized-light`

- `ayu-light`

- `material-light`

- `one-light`

- `coldark-cold`

- `tokyonight-day`

- `kanagawa-lotus`

- `rose-pine-dawn`

- `dawnfox`

- `dayfox`

- `everforest-light`

- `oxocarbon-light`

- `emacs`

- `base16-ocean-light`

## Available fonts

The following fonts are available out of the box:

| Font            | Style      | Metric equivalent |
| --------------- | ---------- | ----------------- |
| Carlito         | Sans-serif | Calibri           |
| Arimo           | Sans-serif | Arial             |
| Caladea         | Serif      | Cambria           |
| Noto Sans       | Sans-serif | —                 |
| DejaVu Sans     | Sans-serif | —                 |
| Liberation Mono | Monospace  | Courier New       |
| Cousine         | Monospace  | —                 |

Use these font families in your custom CSS or HTML templates. To use a custom font, upload the font file as a multipart part and reference it with `@font-face` in your CSS or HTML template.
---

## Related pages

- [DOCX templating API](/guides/dws-processor/tools-and-api/docx-templating-api.md)
- [Document-to-image API](/guides/dws-processor/tools-and-api/document-to-image-api.md)
- [Tools and APIs](/guides/dws-processor/tools-and-api.md)
- [PDF generator API](/guides/dws-processor/tools-and-api/pdf-generator-api.md)
- [Image-to-PDF API](/guides/dws-processor/tools-and-api/image-to-pdf-api.md)
- [Office-to-PDF API](/guides/dws-processor/tools-and-api/office-to-pdf-api.md)
- [PDF-to-image API](/guides/dws-processor/tools-and-api/pdf-to-image-api.md)
- [PDF OCR API](/guides/dws-processor/tools-and-api/pdf-ocr-api.md)
- [PDF security API](/guides/dws-processor/tools-and-api/pdf-security-api.md)
- [Redaction API](/guides/dws-processor/tools-and-api/redaction-api.md)
- [PDF-to-PDF/A API](/guides/dws-processor/tools-and-api/pdf-to-pdfa-api.md)
- [PDF watermark API](/guides/dws-processor/tools-and-api/pdf-watermark-api.md)
- [PDF/UA auto-tagging API](/guides/dws-processor/tools-and-api/pdfua-api.md)

