---
title: "Export to PDF plugin"
description: "The Export to PDF feature provides the ability to generate a PDF file directly from the editor."
canonical_url: "https://www.tiny.cloud/docs/tinymce/latest/exportpdf/"
md_url: "https://www.tiny.cloud/docs/tinymce/latest/exportpdf/index.md"
version: "latest"
last_updated: "2026-07-02T01:24:13Z"
tokens: 4357
---
# Export to PDF plugin

> **Note:** This plugin is only available as a [paid add-on](/tinymce/features/export-pdf/) to [a TinyMCE subscription](/pricing).
The Export to PDF feature collects the HTML generated with the `tinymce.editor.getContent()` method and combines it with the default editor content styles along with the styles provided in the plugin configuration. The combined content and styles are then processed by the included server-side converter service, which can be either self-hosted or cloud-based. Following this processing, a PDF file is generated, which is subsequently returned to the user’s browser, enabling them to save it onto their disk or drive.

## Backwards compatibility and conversion

The plugin always uses the v2 API endpoint (`/v2/convert/html-pdf`). Two option formats are supported:

- **Flat format** – Top-level properties such as `format`, `margin_top`, `header_html`, and `footer_html`. Existing integrations using this format continue to work without changes. The plugin converts flat options to the nested structure automatically before the request.
- **Nested format** – Set `version: '2'` to use the nested structure and access features such as per-page headers and footers, PDF metadata, security, and digital signatures.

Both formats produce equivalent output when configured for the same result. Requires TinyMCE 8.4.0 or newer for v2 API support and automatic conversion.

## Interactive example

**Example**

```js
tinymce.init({
  selector: 'textarea.exportpdf-flat',
  height: '800px',
  plugins: [
    "exportpdf", "advlist", "anchor", "autolink", "charmap", "code", "codesample", "fullscreen",
    "help", "image", "insertdatetime", "link", "lists", "media",
    "preview", "searchreplace", "table", "visualblocks",
  ],
  toolbar: "undo redo | exportpdf | styles | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
  image_caption: true,
  exportpdf_converter_options: {
    format: 'A4',
    margin_top: '1in',
    margin_right: '1in',
    margin_bottom: '1in',
    margin_left: '1in'
  }
});

tinymce.init({
  selector: 'textarea.exportpdf-nested',
  height: '800px',
  plugins: [
    "exportpdf", "advlist", "anchor", "autolink", "charmap", "code", "codesample", "fullscreen",
    "help", "image", "insertdatetime", "link", "lists", "media",
    "preview", "searchreplace", "table", "visualblocks",
  ],
  toolbar: "undo redo | exportpdf | styles | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
  image_caption: true,
  exportpdf_converter_options: {
    version: '2',
    document: {
      size: 'A4',
      orientation: 'portrait',
      margins: {
        top: '1in',
        right: '1in',
        bottom: '1in',
        left: '1in',
        enable_mirror_margins: true
      }
    },
    metadata: {
      title: 'Streamline LMS Overview',
      author: 'TinyMCE',
      subject: 'Learning Management System',
      keywords: [ 'LMS', 'education', 'Streamline' ]
    }
  }
});
```

## Basic setup using the Tiny Cloud service

To add the Export to PDF plugin to the editor, add `exportpdf` to the `plugins` option in the editor configuration.

Example:
```js
tinymce.init({
  selector: 'textarea',
  plugins: 'exportpdf',
  toolbar: 'exportpdf',
  // Required for the cloud-based Export to PDF plugin with Tiny Cloud
  // Create a JWT key in the Customer Portal for trial functionality to enable watermark-free exports during the trial period
  exportpdf_token_provider: () => {
    return fetch('http://localhost:3000/jwt', { // specify your token endpoint
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
    }).then(response => response.json());
  },
});
```

> **Note:** For information on bundling this plugin with module bundlers, see [Bundling TinyMCE - Overview](../bundling-guide/).
For more infomation on the exportpdf_token_provider option, see [exportpdf_token_provider](#exportpdf-token-provider).

> **Important:** The Export to PDF plugin **requires** JWT authentication when using the Tiny Cloud service.
> 
> **Authentication Setup:**
> 
> 1. Create a JWT key in the Customer Portal
> 2. Configure the `exportpdf_token_provider` option to specify the endpoint for retrieving your JWT token
> For more information on how to set up JWT authentication with Export to PDF, see examples: [Export to PDF with JWT authentication (Node.js)](../export-to-pdf-with-jwt-authentication-nodejs/) or [Export to PDF with JWT authentication (PHP)](../export-to-pdf-with-jwt-authentication-php/)
> 
> **Trial period behavior**
> 
> - **Trial Period:**
> 
> - With JWT: Full functionality, unlimited usage, no watermarks.
> - Without JWT: Full functionality with watermarks.
> - **After Trial:**
> 
> - With Export to PDF add-on + JWT: Full functionality (subscription-based)
> - Without add-on: Plugin entitlements are `disabled` and functionality is no longer available.
> Visit the [account portal](/auth/login/) to obtain your JWT key and test full functionality.

> **Note:** When using the cloud-hosted service behind a firewall or forward proxy, ensure `*.tiny.cloud` is allowlisted and that required HTTP headers are not stripped. See [Firewall and proxy allowlisting](../tinymce-and-csp/#firewall-and-proxy-allowlisting) for details.

## Basic setup using the self-hosted service

To use the self-hosted version of the Export to PDF plugin, you need to set the `exportpdf_service_url` option to the URL of the service.

Example:
```js
tinymce.init({
  selector: 'textarea',
  plugins: 'exportpdf',
  toolbar: 'exportpdf',
  exportpdf_service_url: 'http://localhost:8080/' // Update with the URL of the service you are using such  as 'http://myserver.com/'
});
```

> **Important:** The `exportpdf_service_url` option automatically appends `/v2/convert/html-pdf` to the URL provided, so only the base URL is required. For example, if the service is hosted at `http://localhost:8080/v2/convert/html-pdf`, the `exportpdf_service_url` option should be set to `http://localhost:8080/`. When using in production, ensure that `exportpdf_service_url` is updated to the production URL such as `https://myserver.com/`.

## Additional Configuration

> **Note:** Page break support To ensure page breaks work correctly in exported documents, configure the `pagebreak_separator` and `pagebreak_split_block` options:
> 
> ```js
> tinymce.init({
> selector: 'textarea',
> plugins: 'exportpdf',
> toolbar: 'exportpdf',
> pagebreak_separator: '<div style="break-after: page"></div>',
> pagebreak_split_block: true,
> // ... other configuration options
> });
> ```
> For PDF exports, ensure your content includes proper page break elements that will be converted to PDF page breaks.

## Export-specific content filtering

To generate content for export, the Export to PDF plugin calls the `tinymce.editor.getContent()` method with an `export` property set to `pdf`. TinyMCE adds this `export` property to the data for the [`GetContent` event](../events/#editor-core-events) and for serializer node filters. A serializer node filter or a `GetContent` event handler can read the `export` property to filter content during a Export to PDF export only, without changing the result of a standard `tinymce.editor.getContent()` call.

The following serializer node filter removes `footer` elements during a Export to PDF export:

```js
editor.serializer.addNodeFilter('footer', (nodes, name, args) => {
  if (args.export === 'pdf') {
    nodes.forEach((node) => node.remove());
  }
});
```
A `GetContent` event handler can read the same `export` property:

```js
editor.on('GetContent', (e) => {
  if (e.export === 'pdf') {
    e.content = removeFooterFromHtml(e.content);
  }
});
```

## Options

The following configuration options affect the behavior of the Export to PDF plugin.

### `exportpdf_service_url`

The Export to PDF plugin uses an HTML-to-PDF converter service to generate `document-name.pdf` files.

This option is **required** when configuring the Export to PDF plugin for `on-premise` setups. If you require access to this feature, please [contact us](/contact/). For detailed instructions on deploying the Export to PDF service server-side component using Docker, refer to the [on-premises documentation](../individual-export-to-pdf-on-premises/).

> **Important:** On-premises deployments require a Docker image version that supports the v2 API (`/v2/convert/html-pdf`). Upgrade to the latest image or a v2-compatible version to use TinyMCE 8.4.0 or newer with the Export to PDF plugin.

> **Tip:** When using a custom host, set the `exportpdf_service_url` option in your TinyMCE configuration to match your host. For example, if your custom host is `mycustomhost.com`, set the URL to `https://mycustomhost.com/`.
**Type:** `String`

#### Example: Setting up `exportpdf_service_url`

```js
tinymce.init({
  selector: 'textarea',
  plugins: 'exportpdf',
  toolbar: 'exportpdf',
  exportpdf_service_url: '<service_url>' // required for On-premise setups only
});
```

### `exportpdf_token_provider`

The `exportpdf_token_provider` option enables integration with a token-based authentication service for exporting PDF documents. It provides a mechanism to fetch an authentication token from a specified endpoint. This ensures that the export process can securely communicate with the server.

**Type:** `Function`

**Default value:** `undefined`

**Return data:** [`Token` object](#data-structure)

#### Example: using `exportpdf_token_provider`

```js
tinymce.init({
  selector: 'textarea',
  plugins: 'exportpdf',
  toolbar: 'exportpdf',
  exportpdf_token_provider: () => { // required when using the Export to PDF plugin with Tiny Cloud.
    return fetch('http://localhost:3000/jwt', { // specify your token endpoint
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
    }).then(response => response.json());
  },
});
```

#### Data structure for the JWT token

The object containing the valid encoded token must match the following structure:

```js
{
  token: "<encoded JWT string>"
}
```

| Field | Type | Required? | Description |
| --- | --- | --- | --- |
| `token` | `string` | required | A Base64-encoded JSON Web Token (JWT) used for authentication and authorization. |

### `exportpdf_converter_options`

Configures page layout, headers, footers, and other PDF output options. The editor sends this configuration to the converter service when exporting.

**Type:** `Object`

> **Tip:** **Which format to use**
> 
> - **Flat format** – Use for existing integrations (no changes required) or when a simple structure is preferred. Properties such as `format`, `margin_top`, `header_html` at the top level.
> - **Nested format** – Use for new integrations or when per-page headers, PDF metadata, security, or digital signatures are needed. Set `version: '2'` and organize options under `document`, `headers`, `footers`, `metadata`.
Both formats use the same API endpoint. Flat-format options are converted to the nested structure automatically before the request.

> **Note:** Requires TinyMCE 8.4.0 or newer. On-premises deployments require a Docker image version that supports the v2 API.

#### Flat format

Top-level properties: `format`, `margin_top`, `margin_right`, `margin_bottom`, `margin_left`, `header_html`, `footer_html`, `header_and_footer_css`, `page_orientation`, `wait_for_network`, `wait_time`, `base_url`, `extra_http_headers`. Supported for backward compatibility.

> **Note:** As of TinyMCE 7.5.0, the `exportpdf_converter_options` setting now comes with a default value set to the following:
**Default value (flat format):**
```js
{
  format: 'Letter',
  margin_top: '1in',
  margin_right: '1in',
  margin_bottom: '1in',
  margin_left: '1in'
}
```
Example: flat format
```js
tinymce.init({
  selector: 'textarea',
  plugins: 'exportpdf',
  toolbar: 'exportpdf',
  exportpdf_service_url: '<service_url>', // required if using On-premises service
  exportpdf_converter_options: {
    header_html: '<p>HEADER</p>', // example
    header_and_footer_css: 'p { color: blue }', // example
  },
})
```

#### Nested format

Set `version: '2'` to use the nested structure. Access per-page headers and footers, PDF metadata, security, and digital signatures.

**Default value (nested format):**
```js
{
  version: '2',
  document: {
    size: 'Letter',
    margins: {
      top: '1in',
      right: '1in',
      bottom: '1in',
      left: '1in'
    }
  }
}
```
**Main option groups:**

| Option | Description |
| --- | --- |
| `document` | Page size, orientation, and margins |
| `headers` / `footers` | Per-page headers and footers (`default`, `first`, `odd`, `even`) with `html` and `css` |
| `metadata` | PDF metadata (`title`, `author`, `subject`, `keywords` array, `custom_fields`) |

**Additional options:**

- `rendering` – `wait_for_network`, `wait_time`
- `security` – `owner_password` (password protection)
- `signature` – `certificate`, `certificate_password` (digital signing; cannot be used with `security`)
- `base_url`, `extra_http_headers`, `disable_compression`

For full details, see the [PDF Converter API documentation](https://exportpdf.api.tiny.cloud/v2/convert/docs#section/Export-to-PDF-(v2)/Configuration).

Example: per-page headers and footers
```js
tinymce.init({
  selector: 'textarea',
  plugins: 'exportpdf',
  toolbar: 'exportpdf',
  exportpdf_service_url: '<service_url>',
  exportpdf_converter_options: {
    version: '2',
    document: {
      size: 'Letter',
      orientation: 'portrait',
      margins: {
        top: '2cm',
        bottom: '2cm',
        left: '1cm',
        right: '3cm',
        enable_mirror_margins: true
      }
    },
    headers: {
      default: { html: '<p>HEADER</p>', css: 'p { color: blue }' },
      first: { html: '<p>FIRST PAGE</p>', css: 'p { font-weight: bold }' }
    },
    footers: {
      default: { html: '<p>FOOTER</p>', css: 'p { color: green }' }
    }
  },
});
```
Example: metadata
```js
tinymce.init({
  selector: 'textarea',
  plugins: 'exportpdf',
  toolbar: 'exportpdf',
  exportpdf_converter_options: {
    version: '2',
    metadata: {
      title: 'My Document',
      author: 'John Doe',
      subject: 'Quarterly Report',
      keywords: [ 'report', '2024', 'sales' ],
      custom_fields: { 'Department': 'Sales' }
    }
  }
});
```

> **Note:** The `exportpdf_service_url` option must be configured for the Export to PDF plugin to work.

> For comprehensive details, see the [PDF Converter API documentation](https://exportpdf.api.tiny.cloud/v2/convert/docs). For migration guidance from flat to nested format, see the [migration guide](https://exportpdf.api.tiny.cloud/v2/convert/docs#section/Export-to-PDF-(v2)/Migration-guide-from-v1-to-v2).

### `exportpdf_converter_style`

The `exportpdf_converter_style` option allows customization of the styles applied to the exported PDF document, providing flexibility in controlling its appearance.

**Type:** `String`

**Default value:** `''`

#### Example: using `exportpdf_converter_style`

```js
tinymce.init({
  selector: 'textarea.tinymce',
  plugins: 'exportpdf',
  toolbar: 'exportpdf',
  exportpdf_service_url: '<service_URL>', // required if using On-premises service
  exportpdf_converter_options: { // required to support "exportpdf_converter_style"
    header_html: '<h1>First page header.</h1>',
    header_and_footer_css: 'h1 { font-size: 30px; }'
  },
  exportpdf_converter_style: 'p { color: cyan !important }' // requires both "exportpdf_converter_style" and "exportpdf_service_url" to be set.
});
```

> **Tip:** Watermarks can be added to exported PDF documents using CSS.
> 
> - Add the watermark styles to the `exportpdf_converter_style` option, targeting **`body::after`** instead of **`#tinymce::after`** for proper rendering.
> - For more information see: [General/CSS](https://exportpdf.converter.tiny.cloud/docs#section/General/CSS).

#### Example: Adding watermarks to exported PDF documents

```js
exportpdf_converter_style: `
  body::after {
    content: "CONFIDENTIAL";
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-45deg);
    font-size: 48px;
    color: rgba(0, 0, 0, 0.1);
    z-index: 1000;
    pointer-events: none;
  }
`
```

## Toolbar buttons

The Export to PDF plugin provides the following toolbar buttons:

| Toolbar button identifier | Description |
| --- | --- |
| `exportpdf` | Generates a PDF file directly from the editor. |

These toolbar buttons can be added to the editor using:

- The [`toolbar`](../toolbar-configuration-options/#toolbar) configuration option.
- The [`quickbars_insert_toolbar`](../quickbars/#quickbars_insert_toolbar) configuration option.
- [Custom Context toolbars](../contexttoolbar/).

## Menu items

The Export to PDF plugin provides the following menu items:

| Menu item identifier | [Default Menu Location](../menus-configuration-options/#example-the-tinymce-default-menu-items) | Description |
| --- | --- | --- |
| `exportpdf` | Export to PDF | Generates a PDF file directly from the editor. |

These menu items can be added to the editor using:

- The [`menu`](../menus-configuration-options/#menu) configuration option.
- The [`contextmenu`](../menus-configuration-options/#contextmenu) configuration option.
- [Custom Menu toolbar buttons](../custom-menu-toolbar-button/).

## Commands

The Export to PDF plugin provides the following TinyMCE commands.

| Command | Description |
| --- | --- |
| ExportPDF | Generates a PDF file directly from the editor with the filename `document.pdf`. |

Example
```js
tinymce.activeEditor.execCommand('ExportPDF');
```

## API Reference

> Explore the comprehensive API documentation for the Export to PDF Premium plugin at [Export to PDF API Reference Documentation.](https://exportpdf.api.tiny.cloud/v2/convert/docs)
