Skip to content

Latest commit

 

History

History
104 lines (70 loc) · 4.45 KB

File metadata and controls

104 lines (70 loc) · 4.45 KB

Export to PDF plugin

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 {productname} 8.4.0 or newer for v2 API support and automatic conversion.

Interactive example

liveDemo::exportpdf[]

Basic setup using the {companyname} Cloud service

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

Example:
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());
  },
});

For more information on the exportpdf_token_provider option, see exportpdf_token_provider.

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

Commands

The Export to PDF plugin provides the following {productname} commands.

API Reference

Explore the comprehensive API documentation for the Export to PDF Premium plugin at Export to PDF API Reference Documentation.