Convert ODT with Tiptap

OpenDocument Text .odt is a widely used format in LibreOffice and OpenOffice. Tiptap’s Conversion tools provide three ways to work with ODT files:

  • Editor Import – Convert .odt files directly into Tiptap JSON for in-editor editing.
  • Editor Export – Convert the current Tiptap editor content into an .odt file.
  • REST API – Integrate ODT conversions on the server side or from external services with the ODT Conversion REST API.

Subscription required

These extensions require a valid Tiptap subscription. To install the extension, you need access to our private registry.

Editor ODT Import

To import .odt documents into your editor install the Import extension

npm i @tiptap-pro/extension-import

Add and configure the extension in your editor setup

Configure the extension

// Start with importing the extension
import { Import } from '@tiptap-pro/extension-import'

const editor = new Editor({
  // ...
  extensions: [
    // ...
    Import.configure({
      // The Convert App-ID from the Convert settings page: https://cloud.tiptap.dev/convert-settings
      appId: 'your-app-id',

      // The JWT token you generated in the previous step
      token: 'your-jwt',

      // The URL to upload images to, if not provided, images will be stripped from the document
      imageUploadCallbackUrl: 'https://your-image-upload-url.com',
    }),
  ],
})

Import your first document

// The most simple way to import a file
// This will import the uploaded file, replace the editor content
// and focus the editor
editor.chain().focus().import({ file }).run()

Customize the import behavior

// You can also use the onImport callback to customize the import behavior
editor
  .chain()
  .import({
    file,
    onImport(context) {
      const { setEditorContent, content, error } = context

      // add error handling
      if (error) {
        showErrorToast({ message: error.message })
      }

      // You could also modify the content before inserting it
      content.doc.content.push({ type: 'paragraph', content: [{ type: 'text', text: 'Hello!' }] })

      // you can change the loading state of your application for example
      isLoading = false

      // make sure you call the setEditorContent function if you want to run
      // the default insertion behavior of the extension
      // setEditorContent()
      // but since we modified the content, we need to do the insertion manually
      editor.commands.setContent(content)
    },
  })
  .focus()
  .run()

Options

NameTypeDefaultDescription
appIdstringundefinedThe convert app ID from the Convert settings page: https://cloud.tiptap.dev/convert-settings
tokenstringundefinedThe JWT token generated from your server via secret
imageUploadCallbackUrlstringundefinedThe URL to upload images to, if not provided, images will be stripped from the document, see more info

Commands

NameDescription
importImport a file into the editor

import

Arguments

NameTypeDefaultOptionsDescription
fileFileundefinedAny fileThe file to import
formatstringundefinedgfmNot relevant for the ODT file type
onImportFunctionundefinedfn(context)A callback used to customize the import behavior. The context argument includes information about the content, errors and a setEditorContent function to modify the content

Editor ODT Export

To use the convert extension, you need to install the @tiptap-pro/extension-export package:

npm i @tiptap-pro/extension-export

Configure the extension

// Start with importing the extension
import { Export } from '@tiptap-pro/extension-export'

const editor = new Editor({
  // ...
  extensions: [
    // ...
    Export.configure({
      // The Convert App-ID from the convert settings page: https://cloud.tiptap.dev/convert-settings
      appId: 'your-app-id',

      // The JWT token you generated in the previous step
      token: 'your-jwt',
    }),
  ],
})

Export a document

// Do a simple export to docx
// Supported formats: docx, odt, md and gfm
editor.chain().focus().export({ format: 'docx' }).run()

Customize the export behavior

// You can also use the onExport callback to customize the export behavior
editor.chain().export({
  format: 'docx',
  onExport(context) {
    const { blob, error, download, filename } = context

    // add error handling
    if (error) {
      showErrorToast({ message: error.message })
    }

    // you can change the loading state of your application for example
    isLoading = false

    // you could modify the filename or handle the blob differently here
    // but we will keep them as they are

    // you can trigger a download directly by calling the download method
    download()

    // keep in mind that the download method will only work in the browser
    // and if the blob and filename was changed before must be managed manually
  },
})

Options

NameTypeDefaultDescription
appIdstringundefinedThe convert app ID from the Convert settings page: https://cloud.tiptap.dev/convert-settings
tokenstringundefinedThe JWT token generated from your server via secret

Commands

NameDescription
exportExport the editor content

export

Arguments

NameTypeDefaultOptionsDescription
formatstringundefineddocx,odt,md,gfmThe format you want to export to
contentJSONContentundefinedAny Tiptap JSONThe Tiptap JSON content you want to export
onExportFunctionundefinedfn(context)A callback used to customize the export behavior. The context argument includes information about the blob, filename, errors and a download function to download the document directly